Compaq COBOL AAQ2G1FTK User Manual

Page 308

Advertising
background image

Producing Printed Reports
10.5 Programming a Conventional File Report

Example 10–2 Checking for the Page-Overflow Condition

.
.
.
PROCEDURE DIVISION.
A000-BEGIN.

.
.
.

A100-FIRST-REPORT-ROUTINES.
*
* A901-HEADER-ROUTINE executes whenever the number of lines written exceeds
* the number of lines on the 66-line default logical page.
*

WRITE A-LINE1 AFTER ADVANCING 2 LINES.
ADD 2 TO REPORT1-LINE-COUNT.
IF REPORT1-LINE-COUNT > 65 PERFORM A901-HEADER-ROUTINE.

.
.
.

A500-SECOND-REPORT-ROUTINES.
*
* This routine uses only the first 50 lines of the 66-line report.
*

WRITE A-LINE2 AFTER ADVANCING 2 LINES.
ADD 2 TO REPORT2-LINE-COUNT.
IF REPORT2-LINE-COUNT IS GREATER THAN 50

PERFORM A902-HEADER-ROUTINE.

.
.
.

A901-HEADER-ROUTINE.

WRITE A-LINE1 FROM REPORT1-HEADER-LINE-1 AFTER ADVANCING PAGE.
MOVE 0 TO REPORT1-LINE-COUNT.
ADD 1 TO REPORT1-LINE-COUNT.

.
.
.

A902-HEADER-ROUTINE.

WRITE A-LINE2 FROM REPORT2-HEADER-LINE-1 AFTER ADVANCING PAGE.
MOVE 0 TO REPORT2-LINE-COUNT.
ADD 1 TO REPORT2-LINE-COUNT.

.
.
.

Although the WRITE statement allows you to check for a page-overflow condition,
you can also use a line counter that tracks the number of lines that appear on a
page. Section 10.5.3.2 describes this in more detail.

10.5.3.2 Using a Line Counter

A line counter is another method of tracking the number of lines that appear on a
page. If you define a line counter in the Working-Storage Section of your program,
each time a line is written or skipped the line counter value is incremented by
one.

Your program should contain a routine that checks the line counter value before
it writes or skips the next line. If the value is less than the limit you have set, it
writes or skips. If the value equals or exceeds the limit you have set, the program
executes header routines that allow it to advance to the next logical page.

10–8 Producing Printed Reports

Advertising