Producing Printed Reports
10.5 Programming a Conventional File Report
Once you have defined the logical page, you must handle vertical spacing,
horizontal spacing, and the number of lines that appear on each page so that
you can advance to the next logical page. The following sections discuss these
subjects.
10.5.2 Controlling the Spacing in a Conventional Report
To control the horizontal spacing on a logical page, define every report item from
your report layout worksheet in the Working-Storage Section of your Compaq
COBOL program.
To control the vertical spacing on a logical page, use the WRITE statement. The
WRITE statement controls whether one or more lines are skipped before or after
your program writes a line of the report. For example, to print a line before
advancing five lines, use the following:
WRITE... BEFORE ADVANCING 5 LINES.
To print a line after advancing two lines, use the following:
WRITE... AFTER ADVANCING 2 LINES.
10.5.3 Advancing to the Next Logical Page in a Conventional Report
To advance to the next logical page and position the printer to the page heading
area, you must be able to track the number of lines that your program writes on a
page. The Compaq COBOL compiler lets you control the number of lines written
on a page with the WRITE statement.
The WRITE statement must appear in your Procedure Division and it should
contain either the AFTER ADVANCING PAGE or BEFORE ADVANCING PAGE
clause. Example 10–3 demonstrates the use of the WRITE statement with the
AFTER ADVANCING PAGE clause.
The next two sections discuss how to handle a page-overflow condition and how to
use a line counter to keep track of the number of lines your program writes on a
logical page.
10.5.3.1 Programming for the Page-Overflow Condition in a Conventional Report
A page-overflow condition occurs when your program writes more lines than the
logical page can accommodate. This normal condition lets your program know
when to execute its top-of-page routines. Top-of-page routines should contain
WRITE statements with either the AFTER ADVANCING PAGE or BEFORE
ADVANCING PAGE clause.
These statements determine when a report’s logical page is full, and when the
program prints the last line on a logical page (if you do not want to use all the
lines on a page). Example 10–2 shows two methods that check for the page-
overflow condition:
•
Paragraph A100-FIRST-REPORT-ROUTINES checks for a full page after it
writes a report line. If the page-overflow condition exists, A901-HEADER-
ROUTINE executes.
•
Paragraph A500-SECOND-REPORT-ROUTINES checks if more than 50 lines
exist on the current logical page. If more than 50 lines exist, A902-HEADER-
ROUTINE executes.
In either case, the AFTER ADVANCING PAGE clause in the A901-HEADER-
ROUTINE and A902-HEADER-ROUTINE paragraphs generates the characters
needed for the printer to position itself at the top of the next page heading area.
Producing Printed Reports 10–7