MainframeMaster

Page Numbering

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.

Report Generation
Progress0 of 0 lessons

Why Page Numbers?

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.

Where to Put PAGE: HEADER2 vs TRAILER2

HEADER2 is written at the top of each page; TRAILER2 is written at the bottom of each page. So:

  • Put PAGE in HEADER2= to show the page number at the top of each page (e.g. right-aligned or after a title).
  • Put PAGE in TRAILER2= to show the page number at the bottom of each page (e.g. centered or at the bottom right).
  • You can use PAGE in both if you want the number at top and bottom.

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.

LINES= and Pagination

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.

Basic Syntax: PAGE in HEADER2

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.

text
1
2
3
4
5
6
OUTFIL 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.

Positioning the Page Number

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:

text
1
HEADER2=(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).

Multi-Line Headers and the Slash (/)

In HEADER1, HEADER2, TRAILER1, and TRAILER2, the slash (/) is used to separate lines. So one HEADER2 can have several lines. For example:

text
1
HEADER2=(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.

Page Number in the Trailer (Bottom of Page)

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:

text
1
TRAILER2=(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.

"Page n of m" (Current Page of Total Pages)

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:

text
1
HEADER2=(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.

Page number options
Keyword / ideaMeaning
PAGECurrent page number (1, 2, 3, …). Use in HEADER2 or TRAILER2.
LINES=nLines 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.

Explain It Like I'm Five

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.

Exercises

  1. You want the page number at the top right of an 80-column report. What do you put in HEADER2= and at roughly what position?
  2. Why would PAGE in HEADER1 give the wrong result for multi-page reports?
  3. Your report has LINES=60. How does that affect when PAGE changes from 1 to 2?

Quiz

Test Your Knowledge

1. Where do you put the PAGE keyword to get a page number on every page?

  • In BUILD= only
  • In HEADER2= or TRAILER2=—they repeat on each page, so PAGE shows 1, 2, 3, …
  • In HEADER1 only
  • In SORT FIELDS=

2. What does LINES= have to do with page numbering?

  • Nothing
  • LINES=n defines how many lines per page; without it, page breaks and thus HEADER2/TRAILER2 (and PAGE) may not repeat correctly
  • LINES= is the page number
  • Only for SECTIONS

3. How do you get "Page 2 of 5" style output?

  • Only in a program
  • Use PAGE for the current page; if your product supports a total-page count (e.g. TOTALPAGES or similar), use it in the same HEADER2 or TRAILER2—e.g. 'Page ',PAGE,' of ',TOTALPAGES
  • PAGE only prints once
  • Only in TRAILER1

4. Can you put the page number in the trailer instead of the header?

  • No; only HEADER2
  • Yes; TRAILER2 repeats on each page, so you can use PAGE in TRAILER2= to show the page number at the bottom of each page
  • Only HEADER1
  • PAGE is only for detail lines

5. What does the slash (/) in HEADER2=(/,'Page ',PAGE,...) mean?

  • Division
  • New line—each / starts a new line in the header so you can have multi-line headers
  • Comment
  • Optional