MODULE 10 · BATCH REPORTS · 3/7

Print lines and report files

14 min30 XPExercise

A report is just a sequential output file whose records happen to be meant for people. You give it an FD with one plain record, the print line, and build every line in WORKING-STORAGE before writing it.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. STOCKRPT.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT RPT-FILE ASSIGN TO RPTOUT
               ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD RPT-FILE.
       01 RPT-LINE        PIC X(40).
       WORKING-STORAGE SECTION.
       01 HDG-COLUMNS.
          05 FILLER       PIC X(6)  VALUE "PART".
          05 FILLER       PIC X(12) VALUE "DESCRIPTION".
          05 FILLER       PIC X(7)  VALUE "    QTY".
       01 HDG-RULE        PIC X(25) VALUE ALL "=".
       01 DETAIL-LINE.
          05 DL-PART      PIC X(4).
          05 FILLER       PIC X(2)  VALUE SPACES.
          05 DL-DESC      PIC X(12).
          05 DL-QTY       PIC ZZZ,ZZ9.
       PROCEDURE DIVISION.
           OPEN OUTPUT RPT-FILE
           WRITE RPT-LINE FROM HDG-COLUMNS
           WRITE RPT-LINE FROM HDG-RULE
           MOVE "A100" TO DL-PART
           MOVE "BOLT M8" TO DL-DESC
           MOVE 12500 TO DL-QTY
           WRITE RPT-LINE FROM DETAIL-LINE
           MOVE "B200" TO DL-PART
           MOVE "WASHER" TO DL-DESC
           MOVE 7 TO DL-QTY
           WRITE RPT-LINE FROM DETAIL-LINE
           MOVE SPACES TO RPT-LINE
           WRITE RPT-LINE
           CLOSE RPT-FILE
           STOP RUN.

The dataset RPTOUT now holds:

PART  DESCRIPTION     QTY
=========================
A100  BOLT M8      12,500
B200  WASHER            7

How the pieces fit

  • One FD record, many layouts. The FD has a single PIC X(n) line. Every kind of line (headings, detail, totals) is a separate WORKING-STORAGE group, and WRITE RPT-LINE FROM group copies it in and writes it. Keeping the layouts in WORKING-STORAGE means their VALUE clauses are set once and survive between writes.
  • Columns are arithmetic. A field starts one column after the sum of the sizes before it. Headings over numeric columns are right-aligned by padding the literal: " QTY" in a PIC X(7) puts QTY over the last three digits of a 7-character ZZZ,ZZ9. Write the column plan down before you code it.
  • VALUE ALL "=" fills a field with a repeated character, handy for rules and underlines.
  • Blank lines are lines of spaces: MOVE SPACES TO RPT-LINE then WRITE RPT-LINE.
  • Headings before the loop, totals after it. Accumulate totals in plain numeric WORKING-STORAGE fields (PIC 9(7)V99) and move them to edited fields only when you print.

Why not DISPLAY?

DISPLAY goes to SYSOUT, which is mixed with messages from the runtime and other steps, and has no control over the record length. A report goes to its own dataset (DD) so that JCL can route it: to a printer, to a report archive like CA View or Mobius, or to the next job step. In this course, the grader reads the report dataset back and compares it line by line with the expected report. Trailing spaces don't matter; everything else does.

On the job

Report specs are often handed over as a print chart: a grid with column numbers across the top and the layout drawn in X's and 9's. Translating that into FILLERs and edited fields, column by column, is exactly this lesson. Check your work by counting: the length of each group should match the line length on the chart.

Your task

Produce HR's salary listing as a report dataset.

DD EMPIN — line sequential, 37-byte records: EMP-ID X(5), EMP-NAME X(20), EMP-DEPT X(4), EMP-SALARY 9(6)V99.

DD RPTOUT — line sequential report, 60-byte lines (RPT-LINE).

Build it exactly like this:

EMPLOYEE SALARY LIST

ID    NAME                 DEPT       SALARY
----- -------------------- ---- ------------
E0001 ADA LOVELACE         ENG     85,000.00
E0002 GRACE HOPPER         ENG     92,500.50
E0003 KEN THOMPSON         OPS     61,000.00
E0004 JANE DOE             FIN     58,250.75
                                ------------
EMPLOYEES:   4            TOTAL   296,751.25
Columns Content
1–5 employee ID
7–26 name
28–31 department
33–44 salary, Z,ZZZ,ZZ9.99

Line 2 is blank (write a line of spaces). The total line is EMPLOYEES:, the count as ZZ9, then TOTAL ending in column 31, and the total salary in columns 33–44 with the same picture. Under the salary column, a rule of 12 dashes sits in columns 33–44.

fixed format
Run your program to see its output here. The first visible test's input and datasets are used.
Submit to grade your program against every test.