How to display page 1 of n

245 pts.
AS/400 printing
I'm using AS/400 DDS printer file to print PO. It is using OVERLAYS. How can I print Page 1 of 2, and page 2 of 2.

Answer Wiki

Thanks. We'll let you know when a new response is added.


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.

Phil here
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


Discuss This Question: 6  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Yorkshireman
    If you direct the print to a monitored outq, held, then your monitor can pick up the spoolfile, interrogate it for the total pages, then update the position in the relevant records to insert the page total, finally writing it back to the actual outQ Something like - if your first print does 'Page 001 of xxxx' If position 120 = 'Page' then place total to position 127 I have no idea how the overlays would interact with this, you may need to attach them to the final output, regarding the initial processing as part of the application's report generation.
    6,085 pointsBadges:
  • Koohiisan
    Since I use SQL in my RPG a lot, know how many lines my headers take, and know how many detail lines will fit on a page, I do a count using SQL to get the total # of records my report will pull. I then put that count in my 'pages' field on the report and do my normal processing to actually make the report. In the end, it's not that dissimilar to the 'two pass' method mentioned above, except that the sql count(x) function is employed here. Also, sometimes I'm off by a page or so if I have extra breaks and in line totals in the report, so for those I don't worry about the page count.
    5,045 pointsBadges:
  • Rupshall
    Phil, I'm interested in using "Method 2" as you have it listed, the problem is, on the first pass when I try to write to the closed printer file, I get an I/O error. Am I missing something in your technique?
    10 pointsBadges:
  • philpl1jb
    Wow, it's been quite a while. If that dosn't work .. - first pass issue ovrprtf hold *yes - open file - run pass - get pageno - close file - dltsplf ------- then do second loop.
    54,090 pointsBadges:
  • TomLiotta
    Unless you know how many records will be processed and how many pages will be generated from them, it can't be done without processing the print logic twice. You can do the print logic once without writing to the spooled file, and do it again with the writes enabled. Use a total number of pages from the first time through to insert into the actual output the second time through. You could also generate a temporary spooled file to work with. Put a dummy value like "{XxX}" where the page totals ought to be. Once it's created and closed, use the Spooled File APIs to get it all into user spaces. Run through the spaces and replace all of the dummy values with the actual page total. Use the Spooled File APIs again to put the user spaces back out into the new final spooled file. The temporary spooled file can be deleted. You could put all of the Spooled File API processing into a service program and use it over and over for future reports. Tom
    125,585 pointsBadges:
  • Yorkshireman
    Consider what you're asking. A function starts generating print lines. You want to know how many it will create, before you even print the first one (assuming page 1 has a header) There are only 2 ways to do this 1) Know how many to begin with - if you are listing a file, you can determine the number of records in it, pass this to the function, and calculate the answer. If there are selection criteria - can you simulate them and arrive at a number? 2) Not know how many - if you are selecting records, or printing a variable number of lines per item and so forth. - in this case, you have no option but to process the result, and then post process the resulting spool file, to add the total, in any of the ways suggested. Your design aim should be to minimise the excess amount of processing, so rather than rereading the entire spool file to count pages, say, you process once, keep the number of pages, and then insert this to the desired location. If your print logic is complex involving much DB access, you don't want to run it twice if avoidable. Exactly how to do this is down to programming elegance and choice. Spool file API's as suggested by Tom are probably the best way to go, but the other suggestions are valid, as is writing the 'print' to a workfile, which a subsequent program accesses by key and inserts the page number, producing the 'real' spoolfile as it goes. Any of these Physical file solutions need additional programming and will often be one offs for the particular report, though you can arrive at reusable solutions Enjoy!!
    6,085 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: