Key Takeaways — Chapter 16: Report Writer

  1. Report Writer separates structure from logic. The report's physical layout and control-break hierarchy are defined declaratively in the REPORT SECTION (DATA DIVISION), while the PROCEDURE DIVISION handles only data reading and transformation.

  2. Three statements drive the entire report. INITIATE starts the report and resets accumulators. GENERATE produces report output and triggers all automatic processing. TERMINATE ends the report and produces final footings.

  3. GENERATE handles a cascade of automatic actions. A single GENERATE statement can detect control breaks, produce footings and headings, manage page overflow, accumulate SUM values, and write the detail line — all without procedural code.

  4. SUM cascading eliminates accumulation code. SUM values automatically roll up through the control hierarchy. Account subtotals cascade to branch totals, which cascade to region totals, which cascade to the grand total.

  5. CONTROLS must match the sort order. The control fields listed in the RD entry must be in the same major-to-minor order as the input file's sort sequence. Mismatched order produces incorrect subtotals.

  6. GROUP INDICATE suppresses repeating values. Adding GROUP INDICATE to a detail field causes it to print only on the first line of each control group — a standard report formatting convention.

  7. PAGE-COUNTER is maintained automatically. Report Writer increments this special register with each new page. Reference it with SOURCE IS PAGE-COUNTER in page headings or footings.

  8. USE BEFORE REPORTING extends Report Writer's power. When you need procedural logic before generating a report group (lookups, conditional field values), the USE BEFORE REPORTING declarative provides a clean integration point.

  9. Manual control break programs offer more flexibility but more bugs. The most common bug in manual report programs is the "last group" error — forgetting to print the final control group's subtotals after the read loop ends. Report Writer's TERMINATE handles this automatically.

  10. Choose the right tool for the report. Report Writer excels at standard tabular control-break reports. Manual processing is better for irregular formats, conditional layouts, non-text output (HTML, CSV, XML), and cross-tabular reports.