Supported RPG Features

The reserved words PAGE and PAGE1 through PAGE7 are available as output fields on fixed-format O-specs. Each names an independent page counter: PAGE is counter 0, PAGE1 - PAGE7 are counters 1 - 7. A counter starts at 0 and is incremented by one each time its reserved word is referenced in output, so the first printed value is 1. Referencing the same page word twice on one line yields two consecutive numbers.

The value is rendered zero-suppressed (no leading zeros) and right-justified to the field's O-spec end position - for example 1, not 0001. A bare PAGE field behaves like one edited with edit code Z; applying edit code Z explicitly produces the same result.

A page field may also carry a grouping/decimal edit code (1 - 4, A - D, J - Q) in the O-spec edit-code position, in which case the page number is edited numerically like any numeric output field - so a PAGE field edited with code 1 prints 1,234 at page 1234 (the DECEDIT grouping character; see Output edit codes). The page counter still advances exactly once per reference regardless of the edit code.

A page word is also a settable numeric field: naming it as a calculation result field - the result of Z-ADD, or the target of an EVAL assignment - resets or seeds its counter. The next output reference then renders the assigned value plus one (output still increments once before printing), so Z-ADD 1233 PAGE followed by a PAGE output prints 1234, and EVAL PAGE = 0 restarts numbering so the next reference prints 1. Each page word writes only its own counter (Z-ADD 5 PAGE3 affects PAGE3, not PAGE).

A page word may also be read as a value in a calculation - as an operand of an expression, a factor of a fixed-format opcode, or an argument of a BIF such as %CHAR. A read yields the counter's current value and does not advance it; only an output reference increments (adding one before printing). So after Z-ADD 40 PAGE, Z-ADD PAGE X stores 40 in X while the counter stays 40, and EVAL PAGE = PAGE + 1 reads 40 and stores 41. A page word reads as a 4-digit, zero-decimal numeric field.

MOVE to a page word reseeds the counter with the usual MOVE overlay semantics against its current value: without (P), the source's rightmost digits overlay the counter's low-order positions and its high-order digits are preserved (MOVE 567 PAGE turns a counter of 1200 into 1567); with (P), the high-order positions are cleared (MOVE(P) 7 PAGE sets the counter to 7).

A page word used as the Factor 2 of a MOVE or MOVEL moves its 4-position digit image - zero-filled to those four positions, never widened to the result's length and never narrowed to the value's own magnitude. The move then follows the ordinary character rules: MOVE right-aligns the four characters in the result and leaves any positions to their left untouched, MOVEL overlays the leftmost four and leaves the rest untouched, and a result narrower than four positions keeps the rightmost characters. With a counter of 1233 and an 8-position result that started blank, MOVE PAGE yields ␣␣␣␣1233 and a following MOVEL PAGE yields 12331233; moving into a 3-position result yields 233. As with any other calculation read, neither form advances the counter.

A page word named as a program-described input-specification field seeds the counter from record data: naming PAGE (or PAGE1 - PAGE7) in the field-name area of an I-spec field-description line reads the value from the record image during the cycle's field-movement step. The next output reference then prints the seed plus one (output still increments once before printing).

Fixed-format example - reset the counter to start numbering at 100, then print a header on each page:

     FQSYSPRT   O    F  132        PRINTER
     C                   Z-ADD     99            PAGE
     C                   EXCEPT    HEADER
     C                   SETON                                        LR
     OQSYSPRT   E            HEADER
     O                                           10 'PAGE:'
     O                       PAGE                20