May 2007 Technical Tip Page Break Logic and PL/I

Sometimes associates receive training in a subject long before they need it. Today I had a former student ask me to explain page break logic and to demonstrate how it is done in PL/I. Here is the explanation I gave her...

When declaring the report file, be sure to specify the PRINT option as this is required if subsequent PUT statements are to use the PAGE option (explained below):


DCL REPORT  FILE  OUTPUT  STREAM  PRINT;

Page break logic requires three variables: one for the current page number, one for the actual number of lines printed on the current page, and one for the maximum number of lines allowed on a page. (I usually use 50 as a maximum; your number may vary.)


DCL PGS     FIXED DEC(3)  INIT(0); 
DCL LNS     FIXED DEC(3)  INIT(0); 
DCL MAXLNS  FIXED DEC(3)  INIT(50); 

Before printing a line, check to see if the page is full. If so then print a new set of headings:


IF (LNS >= MAXLNS) THEN CALL HDGS; 

Increment the line counter after each PUT statement:


PUT FILE(REPORT) SKIP EDIT(variables here) (formats here);
LNS = LNS + 1;

Within the headings routine, increment the page count, write the heading line(s) (one of which will usually include the page count), then reset the line count. The PAGE option on the PUT statement causes the page break to occur.


HDGS: PROC;
   PGS = PGS + 1;
   PUT FILE(REPORT) PAGE  
       EDIT('MY REPORT', 'PAGE', PGS)
       (COL(1), A, COL(70), A, COL(74), F(3,0));
   LNS = 0;
   END; /* HDGS */

Some people count the headings lines themselves, so the reinitialization might be LNS = 5 but I figure "headings are free" and use LNS = 0 instead.

The mainframe is alive and well! PL/I, COBOL, Assembler, CICS or JCL: we hope you will consider Caliber Data Training when deciding upon a mainframe training provider.


Go to the articles index. Written by Bill Qualls. Copyright © 2007 by Caliber Data Training 800.938.1222