The Report Writer
RD and REPORT
The Report Writer builds paginated output from declarations. The FD declares the file with REPORT IS, and the RD in the REPORT SECTION describes the report itself:
FILE SECTION.
FD REPORT-FILE REPORT IS PAYROLL-REPORT.
01 REPORT-RECORD PIC X(80).
REPORT SECTION.
RD PAYROLL-REPORT
CONTROL IS FINAL WS-DEPT
PAGE LIMIT IS 60 LINES.
Report groups
Report groups describe the lines: PAGE HEADING at the top of each page, DETAIL for every row, and CONTROL FOOTING when a control field changes. LINE, COLUMN, and SUM do the layout and the math:
01 DETAIL-LINE TYPE DE.
02 LINE PLUS 1 COLUMN 1 PIC X(10) SOURCE WS-DEPT.
02 COLUMN 12 PIC $$$,$$9.99 SUM WS-PAY.
GENERATE
In PROCEDURE DIVISION, INITIATE starts the report, GENERATE emits a group, and TERMINATE finishes it. GENERATE DETAIL-LINE prints one row, and the Report Writer automatically inserts headings, page breaks, and control footings as it goes:
OPEN OUTPUT REPORT-FILE.
INITIATE PAYROLL-REPORT.
GENERATE DETAIL-LINE.
TERMINATE PAYROLL-REPORT.
CLOSE REPORT-FILE.
The code on this page was run with GnuCOBOL 3.2.0 on Alpine Linux 3.24.3 (x86_64) in a Docker container.
Article author: Arthur Isaev