Running totals power batch reporting—department gross pay, record counts, error tallies. The ADD statement increments a numeric accumulator in one readable line: ADD GROSS TO DEPT-TOTAL. No temporary variable required when grammar allows ADD value TO field directly. COBOL programmers recognize ADD TO immediately; assignment enthusiasts write DEPT-TOTAL = DEPT-TOTAL + GROSS instead. Both express accumulation when target and source types align. ADD belongs in Activity procedural logic inside JOB loops—not in Library, not in REPORT TITLE. Misplacing ADD before fields initialize yields wrong totals; forgetting to zero accumulators at control break boundaries poisons subtotals. This page teaches ADD syntax variants, contrast with + operator and SUM statement, implied decimal behavior on packed fields, counter increments ADD 1 TO REC-COUNT, interaction with IF filters, overflow risks, and testing patterns auditors use to reconcile ADD totals against SUM report lines.
Core form adds one value into one target field. ADD source TO target increases target by source amount. Source may be field name or literal. Some grammars allow ADD A B TO C adding sum of A and B into C—verify Language Reference for multi-operand forms on your release. ADD executes immediately when reached—unlike SUM which defers to report writer timing on CONTROL breaks.
12345JOB INPUT PAYROLL IF GROSS GT 0 ADD GROSS TO DEPT-TOTAL ADD 1 TO EMP-COUNT END-IF
| Form | Example | Notes |
|---|---|---|
| ADD statement | ADD GROSS TO TOTAL | Statement keyword TO |
| Assignment + | TOTAL = TOTAL + GROSS | Expression on right side |
| ADD literal | ADD 1 TO LINE-COUNT | Common counter increment |
| SUM on REPORT | SUM GROSS on CONTROL | Report writer not ADD |
Working storage accumulators need zero before loop unless VALUE on DEFINE sets initial state. At department control break, reset DEPT-TOTAL when logic tracks per-dept subtotals manually—report SUM handles break totals declaratively but manual ADD paths require explicit MOVE 0 TO DEPT-TOTAL or ADD negative prior total patterns avoided by clear reset. JOB activity RESET on W fields may reinitialize at activity start per variable lifetime rules.
ADD GROSS TO TOTAL when both P 2 adds at cents scale. Adding P 2 to N 5 may convert per rules—test in dev. Overflow when TOTAL exceeds field size causes size error or wrap—size TOTAL wide enough for maximum run. ADD to packed field with invalid input data from file causes data exception—validate with testing functions before ADD on untrusted amounts.
ADD 1 TO REC-COUNT increments processed records. ADD 1 TO ERR-COUNT when validation fails. Counters feed trailer records and DISPLAY diagnostics. Integer N or P 0 fields suit counts; do not use implied decimal P 2 for counts unless intentional. Compare REC-COUNT to trailer control field at EOF for reconciliation.
1234567JOB INPUT INFILE ADD 1 TO REC-COUNT IF INVALID-REC EQ Y ADD 1 TO BAD-COUNT ELSE ADD AMT TO GOOD-TOTAL END-IF
ADD only runs when control reaches it—guard with IF DEPT EQ 911 before ADD to dept accumulator. PERFORM CALC PROC may contain ADD steps reused across branches. Do not ADD inside report AFTER-BREAK when SUM already maintains same total—double-count risk unless intentional cross-check.
SUM on REPORT declarative line accumulates during report processing aligned with CONTROL field breaks—formatted on break lines automatically. ADD in JOB builds working totals for WRITE to extract file, DISPLAY, or conditional logic before PRINT. Some programs ADD in JOB for audit and rely on SUM for printed subtotals—totals must match or document intentional difference.
ADD is putting more coins in a jar. The jar already had some coins; ADD drops in the new amount and the jar now has the old plus the new. Saying TOTAL = TOTAL + GROSS is the same idea with different words. SUM on the report is a special jar the report machine fills when the department name changes on the page.
1. ADD GROSS TO DEPT-TOTAL means:
2. ADD statement versus TOTAL = TOTAL + AMT assignment:
3. ADD on packed P 2 fields:
4. ADD in JOB loop over input file:
5. ADD versus SUM on REPORT: