Skip to content

Page Counter

This special register contains the number of the current page.

page counter

Uses of Page Counter

  • PAGE-COUNTER contains the number of the current page. It is set to 1 by the INITIATE statement and, if your report has a PAGE LIMIT clause, is incremented by 1 on each page advance after the initial one. So its value is 1 on the first page, 2 on the second, and so on. The incrementing takes place between the production of your PAGE FOOTING group, if you defined one, and your PAGE HEADING group, if you defined one. So accessing PAGE-COUNTER in a USE BEFORE REPORTING Declarative section for a PAGE HEADING, for example, yields the value that applies to the new page. The TERMINATE statement leaves PAGE-COUNTER unchanged.

  • You may treat PAGE-COUNTER as a numeric location (implicit PICTURE S9(9) COMP SYNC) in any SOURCE expression or condition. For example, to print the page number anywhere in the page, write: PIC ZZZ9 SOURCE IS PAGE-COUNTER.

    You can change the value of PAGE-COUNTER at any time. Just treat it as any numeric data item (except that report writer defines it automatically). As an example, if you want to restart your page numbering from 1, after each control break, code MOVE ZERO TO PAGE-COUNTER in a Declarative SECTION for the CONTROL HEADING, so that when report writer next does a page advance it will increment it from zero to one.

  • Like all of the special registers except COLUMN-COUNTER, a PAGE-COUNTER is maintained separately for each report, because all your reports are completely independent of each other. This also means that you must occasionally qualify PAGE-COUNTER if you have more than one report in the program. You do this by using report-name as a qualifier, as shown in the format at the head of this section.

    You need a qualifier only if there is ambiguity, that is, in the main-line PROCEDURE DIVISION. In the Report Group Descriptions and in a USE BEFORE REPORTING directive section report writer assumes that you mean "IN current-report". However, you may still use a qualifier even in those cases, for instance when you want to access the PAGE-COUNTER of a different report. More information on Multiple Reports will be found later.

  • If your report contains a REPORT HEADING that is on a page by itself, the value of PAGE-COUNTER for the first page of details will be 2, since page 1 is occupied by the REPORT HEADING. If you want PAGE-COUNTER to be 1 on the first page of details, you will need to code MOVE ZERO TO PAGE-COUNTER after the Initiate statement.

Compatibility

OS/VS and DOS/VS COBOL require PAGE-COUNTER to be qualified wherever it is used if your program contains more than one RD.

Back to top