Showing posts with label Easytrieve CONTROL. Show all posts
Showing posts with label Easytrieve CONTROL. Show all posts

Monday, 29 July 2013

Easytrieve Report Calculation: Arithmetic, Totals, and SUM

An Easytrieve report often starts with fields from an input file, then adds one or two calculated values before printing the line. A payroll report may read GROSS, subtract tax and deductions, print NET-PAY, and then total the amount by department. The calculation is small, but a wrong decimal position or missing parenthesis can make every report line wrong.

Easytrieve report calculation diagram showing input fields, work calculation, report line, CONTROL, and SUM totals
Calculate, print, total.

What Easytrieve report calculation means

Easytrieve lets you calculate values in the JOB activity and print them in a report. The common pattern is simple: define input fields, define working fields, calculate the working fields, then print them through a LINE statement.

Report totals are a separate feature. Easytrieve can total quantitative fields on control reports, and the SUM statement can limit which fields are totaled. Broadcom also documents TALLY as a count field available in report output and summary files.

Arithmetic operators

Easytrieve arithmetic uses the standard operators for multiplication, division, addition, and subtraction. Code spaces around the operators so the statement remains readable in listings and reviews.

Operator Meaning Example
* Multiplication NET = HOURS * RATE
/ Division AVG = TOTAL / COUNT
+ Addition TOTAL = BASE + BONUS
- Subtraction NET = GROSS - TAX

Order of calculation

Multiplication and division are evaluated before addition and subtraction. When the intended order is not obvious, use parentheses. Parentheses also help the next developer see the business rule without doing mental arithmetic.

RESULT = GROSS - AMT * 1.3

* Same as:
RESULT = GROSS - (AMT * 1.3)

* Different from:
RESULT = (GROSS - AMT) * 1.3

For finance reports, do not rely on readers knowing the default order. Code the parentheses that match the rule from the specification.

Define working fields for calculated values

Use working fields for values that do not come directly from the input record. Give the field a clear length, type, and decimal count. In old Easytrieve jobs, many report errors come from a receiving field that is too small or has the wrong decimal places.

FILE PERSNL FB(150 1800)
     DEPT        1   3 N
     EMPNO       9   5 N
     GROSS      94   4 P 2
     TAX        98   4 P 2

NET-PAY          W   6 P 2

The example defines NET-PAY as a working field with two decimal places. That makes it suitable for a payroll-style calculated amount.

Simple calculation example

This small report calculates net pay for each input record and prints the department, employee number, gross pay, tax, and net pay.

JOB INPUT PERSNL NAME PAY-RPT
    NET-PAY = GROSS - TAX
    PRINT PAYRPT

REPORT PAYRPT
    TITLE 1 'PAY CALCULATION REPORT'
    LINE DEPT EMPNO GROSS TAX NET-PAY

Keep calculations close to the PRINT statement when possible. That makes it easier to prove which value was printed on the report line.

Rounding calculated values

The original post mentioned a rounding factor. A common Easytrieve technique is to add a value such as .005 before assigning to a field with two decimal places. That rounds a positive amount to cents.

NET-PAY = (GROSS - TAX) + .005

Use this carefully. Confirm the rule for negative values, credits, and site-specific finance standards before applying the same rounding pattern to every amount.

Report totals with CONTROL and SUM

For control reports, Easytrieve can print totals when a control field changes. Broadcom guidance for subtotals uses SEQUENCE followed by CONTROL. Broadcom also documents that SUM can select which quantitative fields are totaled instead of totaling every eligible field on the report line.

REPORT PAYRPT
    SEQUENCE DEPT
    CONTROL DEPT
    SUM GROSS TAX NET-PAY
    TITLE 1 'PAY TOTALS BY DEPARTMENT'
    LINE DEPT EMPNO GROSS TAX NET-PAY

Use SUM when the report line contains numeric fields that should not be totaled, such as employee number, region code, or account code.

Using TALLY for counts

TALLY is useful when the report needs a count as well as an amount. For example, a department control report can show how many employee records were read for each department and the total net pay for that department.

REPORT PAYRPT SUMMARY
    SEQUENCE DEPT
    CONTROL DEPT
    SUM NET-PAY
    HEADING TALLY 'COUNT'
    LINE DEPT TALLY NET-PAY

This separates count from amount. Do not use an employee number or a code field as a pretend count.

Common mistakes

Forgetting decimal places

If NET-PAY is defined with no decimal places, cents can be lost or rounded in a way the report owner did not expect. Match the working field to the business value.

Totaling identifier fields

Numeric codes are not always amounts. Use SUM to keep Easytrieve from totaling fields such as employee number, department number, or account code.

Hiding calculation rules

A report line that prints NET-PAY should make the calculation visible in the job activity. Avoid spreading the same calculation across many unrelated statements.

Review checklist

  • Check every calculated field length, type, and decimal count.
  • Use parentheses where the rule has more than one operator.
  • Keep calculated work fields near the report that prints them.
  • Use SUM to total only real amount or quantity fields.
  • Use TALLY for counts instead of totaling an identifier.
  • Compare a few report lines with hand-calculated values before promotion.

Related Mainframe Forum guides

For nearby topics, read Easytrieve Basic Reporting, Easytrieve Basic Report Field Definition, Easytrieve Basic Report Edit Field Definition, Easytrieve Basic Conditions, Easytrieve Sorting, and Easytrieve VSAM File Handling.

External references

Broadcom documents subtotals and grand totals, SUMFILE fields, and HEADING usage in report definitions.

FAQ

How do I calculate a field in Easytrieve?

Define a working field, assign it in the JOB activity, and include it on the report LINE statement.

Does Easytrieve follow normal arithmetic order?

Yes. Multiplication and division are evaluated before addition and subtraction. Use parentheses when the report rule needs a different order.

How do I print subtotals in Easytrieve?

Use SEQUENCE and CONTROL for a control report. Add SUM when only selected quantitative fields should be totaled.

What is TALLY used for?

TALLY is used as a count field in reports and summary output. It is useful when the report needs record counts by control break.

New In-feed ads