PAGENO operator returns the number of the report page that is currently being printed.
PAGENO does not take any operands:
PRINT COLUMN 40, PAGENO USING "Page &&&"
PAGENO returns a positive integer. This integer corresponds to the number of the current report page.
You can include the PAGENO operator in the PAGE HEADER, PAGE TRAILER, and other report control blocks of a report definition to identify the page numbers of the report output.
4gl cannot evaluate the PAGENO operator outside the FORMAT section of a REPORT program block.
If you to use its returned results in other program blocks, you must assign them to a variable that is not local to the report.
This example program prints the page number on the top and bottom of each report page:
MAIN
DEFINE i INTEGER
START REPORT rep TO SCREEN
FOR i=1 TO 3
OUTPUT TO REPORT rep ()
END FOR
FINISH REPORT rep
END MAIN
REPORT rep ()
OUTPUT PAGE LENGTH 10
TOP MARGIN 0
BOTTOM MARGIN 1
FORMAT
PAGE HEADER
PRINT "This is start of page number: ", PAGENO
ON EVERY ROW
PRINT "This is the page content"
SKIP 6 LINES
PAGE TRAILER
PRINT "This is end of page number: ", PAGENO
END REPORT
This piece of code shows how you can set page numbering so that it will include both the number of the current page and the total number of pages:
SELECT COUNT(*) num FROM customer INTO TEMP temp_table
SELECT * FROM customer, temp_table
FORMAT
FIRST PAGE HEADER
LET x = temp_table/30
PAGE TRAILER
PRINT "Page ", PAGENO USING "<<<" " of ", x USING "<<<"
In this example, the total number of record pages returned by the query is written into a temporary table. The total number of pages is defined by dividing the total number of records by the number of record allowed per page (30). If there is a remainder, the total number of pages is rounded up.
If the total number of pages is 100, the first page will be numbered as
Page 1 of 100
and the last one will be
Page 100 of 100
To calculate the total number of report pages, you need that