Page numbering in DFSORT reports means printing the current page number (1, 2, 3, …) on each page of the report. You do this by using the PAGE keyword inside HEADER2= or TRAILER2= (or both). HEADER2 is the page header and TRAILER2 is the page trailer; both repeat on every page when LINES=n is used, so PAGE is updated for each new page. You combine PAGE with literal text (e.g. "Page ", PAGE) and optionally with positioning (e.g. 60:PAGE to put the number at column 60). Some products also support a total-page count (e.g. "Page 2 of 5"). This page explains how to add page numbers, where to put them, how LINES= affects pagination, and how to format the output. For general pagination (lines per page, page breaks), see the Pagination tutorial.
Printed or PDF reports often have many pages. Without page numbers, it is hard to know if pages are missing or out of order. Putting "Page 1", "Page 2", etc. at the top or bottom of each page makes the report easier to read and to reference. In DFSORT you get this by using the PAGE keyword in the page header (HEADER2) or page trailer (TRAILER2). Because those lines are written once per page, PAGE automatically shows the correct number for that page.
HEADER2 is written at the top of each page; TRAILER2 is written at the bottom of each page. So:
Do not rely on HEADER1 for page numbers. HEADER1 appears only once at the very beginning of the report. So PAGE in HEADER1 would always show 1 (or the first page). For per-page numbering, use HEADER2 or TRAILER2.
Page numbering only makes sense when the report has multiple pages. You control that with LINES=n on the same OUTFIL. LINES=n tells DFSORT how many lines fit on one page. After n lines (including detail lines and any header/trailer lines that count toward the total, depending on product), DFSORT starts a new page and writes HEADER2 (and TRAILER2 if specified) again. So PAGE becomes 2, then 3, and so on. Without LINES=, many products default to a single logical page or a fixed default (e.g. 60 lines); PAGE would still work but you might not see multiple pages. Always specify LINES= when you want clear page breaks and correct page numbers.
In HEADER2= you list the content of the page header. You can use fixed text (literals), positioning (e.g. 40: to start at column 40), and the PAGE keyword. PAGE is replaced by the current page number (1, 2, 3, …). A typical pattern is to put the word "Page" and then PAGE, and optionally the date. Exact syntax is product-dependent; the following is illustrative.
123456OUTFIL FNAMES=REPORT, BUILD=(1,80), HEADER1=(1:'SALES REPORT'), HEADER2=(1:'Page ',PAGE,20:'Date: ',DATE), TRAILER1=(1:'END OF REPORT'), LINES=55
HEADER2 has two parts: the literal "Page " followed by PAGE (so "Page 1", "Page 2", …), and at position 20 the literal "Date: " and the date. LINES=55 means 55 lines per page, so after 55 lines HEADER2 is written again with PAGE incremented. DATE and PAGE syntax may vary by product; see your manual.
You can control where the page number appears by using position notation. In many DFSORT products you specify position:content—e.g. 60:PAGE puts the page number starting at column 60 (right side of an 80-column line). So for a right-aligned page number on an 80-column report you might use:
1HEADER2=(60:'Page ',PAGE)
Or use multiple elements: literal text at one position and PAGE at another. For a centered or right-aligned layout, choose the start position so that "Page n" fits before the end of the record. Exact positioning syntax is product-dependent (e.g. some use column numbers, some use length after position).
In HEADER1, HEADER2, TRAILER1, and TRAILER2, the slash (/) is used to separate lines. So one HEADER2 can have several lines. For example:
1HEADER2=(1:'SALES DETAIL',/,1:'Page ',PAGE,70:DATE)
The first line is "SALES DETAIL"; the second line (after /) has "Page ", PAGE, and the date at position 70. So the page number can be on its own line or on a line with other text. Use / to start a new line wherever you need it.
To put the page number at the bottom of each page, use TRAILER2= with PAGE. TRAILER2 is written at the bottom of each page (after the detail lines for that page). So:
1TRAILER2=(1:'Page ',PAGE)
gives "Page 1", "Page 2", … at the bottom of each page. You can combine with other text or positioning (e.g. 60:\'Page \',PAGE for right-aligned). Some shops prefer the page number in the trailer so the top of each page is clean except for column headers.
To print "Page 2 of 5" you need two values: the current page (PAGE) and the total number of pages. The current page is provided by PAGE. The total number of pages is known only after all records are written. Some DFSORT products provide a keyword (e.g. TOTALPAGES or similar) that is filled in at the end of the report and can be used in HEADER2 or TRAILER2. In that case you would code something like:
1HEADER2=(60:'Page ',PAGE,' of ',TOTALPAGES)
If your product does not support a total-page count, you cannot get "Page n of m" in a single pass. You might run the report twice (first pass to count pages, second to print) or use a post-process to replace a placeholder with the total. Check your DFSORT or ICETOOL documentation for supported keywords.
| Keyword / idea | Meaning |
|---|---|
| PAGE | Current page number (1, 2, 3, …). Use in HEADER2 or TRAILER2. |
| LINES=n | Lines per page; causes page breaks and HEADER2/TRAILER2 to repeat. |
| TOTALPAGES (if supported) | Total number of pages; for "Page n of m" style. Product-dependent. |
Imagine a booklet: each page has a number at the top or bottom so you know "this is page 2." In DFSORT, the booklet is your report. You tell the sort program "start a new page every 55 lines" (LINES=55). On each new page, it prints a header (or footer) that includes the word "Page" and the right number—1 on the first page, 2 on the second, and so on. So the report "numbers the pages" for you.
1. Where do you put the PAGE keyword to get a page number on every page?
2. What does LINES= have to do with page numbering?
3. How do you get "Page 2 of 5" style output?
4. Can you put the page number in the trailer instead of the header?
5. What does the slash (/) in HEADER2=(/,'Page ',PAGE,...) mean?