SUM tells a control report which amounts to add when a break field changes. Without it, every quantitative field on LINE is totaled. With SUM GROSS, the department total line carries gross even if net pay and deductions also print on each detail row. SUM is declarative. It lives in the REPORT block. It does not replace ADD, which updates a work field while the JOB reads records.
| Statement | Role |
|---|---|
| SEQUENCE | Keeps one break value together |
| CONTROL | Names the field that triggers a subtotal |
| LINE | Detail columns; quantitative ones total by default |
| SUM | Optional list of fields that are allowed to total |
This report totals every quantitative field on LINE, because no SUM is present. GROSS, NET-PAY, and DEDUCTIONS each get a department subtotal and a FINAL grand total. EMPNAME does not add. It has no decimal positions.
12345REPORT PAY-RPT LINESIZE 80 SEQUENCE DEPT CONTROL DEPT TITLE 'PERSONNEL BY DEPARTMENT' LINE DEPT EMPNAME GROSS NET-PAY DEDUCTIONS
SUM GROSS overrides that default. Detail lines still show net pay and deductions. The break line and the grand total accumulate gross only.
123456REPORT PAY-RPT LINESIZE 80 SEQUENCE DEPT CONTROL DEPT SUM GROSS TITLE 'SALARY EXPENSE BY DEPT' LINE DEPT EMPNAME GROSS NET-PAY DEDUCTIONS
You can SUM a work field that never appears on LINE, for example an amount the JOB computed and stored before PRINT. List every field you want accumulated. A field left off SUM is left off the total line.
ADD GROSS TO WS-TOTAL inside the JOB updates WS-TOTAL once per record you process. That total exists whether or not you PRINT. SUM runs in the report writer when CONTROL fires or when FINAL totals print. Use ADD when the activity needs a running figure for an IF. Use SUM when the printed register needs subtotals.
123456789JOB INPUT PAYFILE ADD GROSS TO WS-TOTAL PRINT PAY-RPT REPORT PAY-RPT LINESIZE 80 SEQUENCE DEPT CONTROL DEPT SUM GROSS LINE DEPT GROSS
LINE is each marble. CONTROL is a sticky note every time the color changes. With no SUM, you count every kind of marble that has a number on it. SUM is you saying "only count the big ones." The small ones still get listed. They just do not go on the sticky note.
1. SUM belongs:
2. With no SUM, a control report totals:
3. SUM GROSS when LINE also shows NET-PAY means:
4. ADD in the JOB and SUM on the report:
5. A SUM field must appear on LINE: