how to get Page number in specific format in AS400 ( cobol or RPG)

Hi Folks, i have been asked to print the Page number as page : N/X ( i.e the current page number is N out of total X pages). I knew that its possible to display the page number as page : N ( where N is the current page). But how can i pre determine the total pages of report in advance and have it printed in specified format? Please help me out

Answer Wiki

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

If you have a specific file that drives the input and the number of lines printed is the same for each record in the input file, you get get the record count from the file. Then divide that by the nuymber of lines that will print per page, you can get total number of pages.
If you are doing selection from that file, you can use SQL to get a count of how many records you will be selecting.
If the number of lines vary or the number of records selected is based on factors in other files, then this may not be possible.

Discuss This Question: 2  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.
  • philpl1jb
    There are plenty of discussions of the options in the case where you cannot calculate the number of lines. None of these solutions are trival, Phil
    54,090 pointsBadges:
  • TomLiotta
    If it is predictable as CharlieBrowne mentions, then you simply predict it by using whatever gives the correct result, e.g., number of input records. And if it's not predictable, you're into Phil's "none are trivial" cases. If I had to do it, I would print something like {Page nn of {xx}" on each page. The "nn" would be the actual page number, but the "{xx}" would be some identifiable constant that is guaranteed not to be anywhere else in the output except where the page count is intended to be. I would generate the output and close the file. Then I would either retrieve the count of pages from the spooled file attributes or I'd grab the value from wherever I stored it in the program. Finally, I would use the Get Spooled File Data (QSPGETSP) API to get the spooled output into one or more user spaces, and use the appropriate User Space APIs to change each occurrence of "{xx}" to the actual page count, and the Put Spooled File Data (QSPPUTSP) API to re-spool the output. The temporary original spooled copy could be deleted once the new copy is re-spooled. Tom
    125,585 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: