A
report generated from a large data file would typically require more than one
page. Without knowing otherwise, your program would continue to print detail
lines as each record is processed without regard to page boundaries. Thus, only
the first page would have report and column headings. On continuous forms, like
those used in dot-matrix printers, the output would continue through the page
perforations. In addition, it would be difficult to know the page order once
the pages are separated.
Instead
of measuring the page in terms of inches, page planning is commonly done in
terms of lines per page, in which the standard line spacing is 6 lines
per vertical inch. Thus, if you are using an 11-inch form, there are 66 lines
per page. If you want top and bottom margins of 1 inch (6 lines), the body of
your report (including headings and blank lines) would consists of
66 – 6
– 6 = 54 lines
So your program would need appropriate control to
start a new page after 54 lines have been printed on the current page. To do
this, you make the program literally count lines (including the blank ones) as
they are printed. The program must also constantly compare this count to
a pre-determined limit for the maximum lines per page and perform the
paragraph that updates the page number and reprints the headings when that count
exceeds the limit.
WORKING-STORAGE
SECTION.
01
PAGE-CONTROL.
02
LINE-COUNT PIC
99 VALUE 55.
02
MAX-LINES-PER-PAGE PIC
99 VALUE 54.
PROCEDURE
DIVISION.
.
.
.
200-DETAIL-LOOP.
IF LINE-COUNT > MAX-LINES-PER-PAGE,
PERFORM 400-PRINT-HEADINGS
.
.
.
.
WRITE PRINT-LINE FROM DETAIL-LINE AFTER
VAR-SPACING
ADD VAR-SPACING TO LINE-COUNT
MOVE 1 TO VAR-SPACING
.
.
.
400-PRINT-HEADINGS.
.
.
ADD 1 TO PAGE-NBR
MOVE PAGE-NBR TO MH-PAGE
WRITE PRINT-LINE FROM MAIN-HEADING AFTER
PAGE
WRITE PRINT-LINE FROM HDG-2 AFTER 2
WRITE PRINT-LINE FROM HDG-3 AFTER 1
MOVE 2 TO VAR-SPACING
MOVE 4 TO LINE-COUNT