The only way to do that is calculating the number of pages your report will generate and using it in the report it self.
To calculate the number of pages may be difficult depending the format and number of lines in each page.
Method 1. Method described by Wilson can be nightmare of duplicate code for counting and actual printing.
Method 2. Two pass method
Change spoolfile to USROPN
Loop through the print code twice
– first pass spoolfile is not open
– capture final pageNo
– second pass open spool file
– print report using final PageNo from above for MaxPage#
Method 3. After RPG program creates the spool file with the dummy value XXXX for maxPage#
Copy to PF, change, copy to SPLF method
– cpysplf to a flat file
— spool file must be *SCS – no overlays (add later), add LPI and the like at file level only later.
— -flat file must be at least 1 char wider than spool file
— Control character . . . . . . . *FCFC (captures form feed and line spacing)
– RPGLE program does two passes through flat file
— pass 1 find highest page #
— pass 2 add highpg# to Page nnnn to XXXX lines.
- Ovrdbf (QSYSPRT) FileControl(*FCFC) <<– add *AFPDS, Overlays, FileLevel LPI – etc.
- Cpyf FlatFile Qsysprt *replace