Your program needs to be aware of the current setting for LINES so you can test for the end of a page. The current row count is compared to a constant value or to the LINES setting to check for the end of page. The CVAL function is used to place the current line setting in a variable. For example,
SET VARIABLE vLines = (CVAL('LINES'))
Then, an IF statement compares the vLines variable with the vRowCount variable. For example,
IF vRowCount >= .vLines THEN
NEWPAGE
SET VARIABLE vRowCount = 1
SET VARIABLE vRow = 1
SET VARIABLE vColumn = 1
ENDIF
The vRowCount, vRow, and vColumn variables must be reset for each new page. Leave a five line margin at the bottom of the page by comparing vRowCount to vLines minus five. For example,
IF vRowCount >= (.vLines - 5) THEN
NEWPAGE
SET VARIABLE vRowCount = 1
SET VARIABLE vRow = 6
SET VARIABLE vColumn = 5
ENDIF
Margins at the top of the page and on the left side are determined by the initial settings for the vRow and Vcolumn variables.
You can calculate the number of rows to print for the next data item, and compare that to see if all the data will fit on a page. This calculation is used to make sure break header, detail, and break footer information all appear on the same page.
SELECT COUNT(*) INTO vNumToPrint +
FROM transmaster WHERE custid = .vCustid
IF (.vRowCount + .vNumToPrint) >= .vLines THEN
NEWPAGE
SET VARIABLE vRowCount = 1
SET VARIABLE vRow = 6
SET VARIABLE vColumn = 5
ENDIF
There are many different ways to keep track of the number of rows that have been printed on the page. The important thing to remember is that you need to keep track of it and issue the form feed yourself; it does not happen automatically.