MainframeMaster

Generating Headers and Trailers

Generating headers and trailers in DFSORT means adding fixed lines at the top and bottom of your report—titles, column headings, print date and time, page numbers, record counts, and totals. You use OUTFIL with HEADER1 (report header), HEADER2 (page header), TRAILER1 (report trailer), TRAILER2 (page trailer), and with SECTIONS, TRAILER3 (section trailer). Headers and trailers can include positioned text (e.g. 20:'Title'), DATE= and TIME, the PAGE number, and COUNT= or totals in trailers. This page covers the syntax for each type, positioning, multi-line headers, and how to add counts and dates.

Report Generation
Progress0 of 0 lessons

HEADER1 and HEADER2

HEADER1 defines the main report header—one or more lines written at the very beginning of the OUTFIL output. HEADER2 defines the page header: it repeats at the top of each page when you specify LINES=n. Without LINES=, there is no pagination, so HEADER2 typically appears only once (or as defined by the product). Use HEADER1 for the report title and optional print date/time; use HEADER2 for column titles and page number so every page is self-explanatory.

Where each header/trailer appears
TypeWhen it appearsTypical use
HEADER1Once at start of reportReport title, print date/time, opening message
HEADER2Top of each page (with LINES=)Column titles, page number, short title
TRAILER1Once at end of reportRecord count, grand total, closing message
TRAILER2Bottom of each page (with LINES=)Page number, page footer
TRAILER3After each section (with SECTIONS)Section subtotal, section footer

Positioning and Multi-Line Syntax

In HEADER1=, HEADER2=, TRAILER1=, or TRAILER2=, you use position:value to place text at a specific column. For example 20:'Report Title' starts the text at column 20. You can list multiple items separated by commas; the order and position control the layout. Use / (slash) to start a new line. Example:

text
1
2
HEADER1=(20:'Student Details', 37:'Printed on ',DATE=(MD4/),' AT ',TIME)

The first line has "Student Details" at column 20 and "Printed on " followed by the date (format MD4/), then " AT " and the time. DATE= and TIME formats (e.g. MD4, MD4-, Y2Y) are product-specific. The slash in DATE=(MD4/) may denote a date format; check your manual.

HEADER2 with Page Number and Column Titles

For a page header that repeats on each page, use HEADER2 with PAGE (or the product keyword for page number), date, and column titles. Use / to put the column titles on the next line and an underline on the line after that:

text
1
2
3
4
HEADER2=(/,15:'Class X Students details', 40:'Page',PAGE,53:' on ',58:DATE=(MD4-),/, 1:'Std num',11:'Std name',30:'Department',45:'Total marks',/, 1:'-------',11:'--------',30:'----------',45:'-----------')

The first line of HEADER2 is blank (/, then positioned text). The second line has the subtitle, "Page", the page number, " on ", and the date. The next line has column titles; the next has underlines. So each page starts with this block before the detail lines. LINES= must be set (e.g. LINES=60) for HEADER2 to repeat.

TRAILER1: Report Trailer and Count

TRAILER1 is written at the end of the report. It often contains a record count or grand total. The syntax for a count is product-specific; a common form is COUNT=(edit_mask,LENGTH=n) where the edit mask (e.g. M10, M11) formats the count and LENGTH is the output length. Example:

text
1
TRAILER1=(1:'Total records: ',COUNT=(M11,LENGTH=10))

This produces a line that starts with "Total records: " followed by the number of detail records written, formatted with M11 (e.g. leading zeros or blanks). Your product may use different keywords (e.g. TOTAL=, RECORDCOUNT=); see the manual. TRAILER1 can also be a fixed message with no count, or multiple lines using /.

TRAILER2 and TRAILER3

TRAILER2 is the page trailer: it appears at the bottom of each page when LINES= is specified. Use it for "Page n of m" or a short footer. TRAILER3 is used with SECTIONS: it is written after each section (each group of records with the same section key). Use TRAILER3 for section subtotals or a line after each group. The exact syntax for section totals (e.g. subtotal of a numeric field) is product-dependent; refer to control-break and report-totals documentation.

DATE= and TIME Formats

In headers and trailers you can insert the current date and time. DATE=(format) and TIME (often with format options) are replaced at run time. Common date formats include MD4 (MM/DD/YYYY or similar), MD4- (MM-DD-YYYY), Y2Y (year format), and others. TIME often produces HH:MM:SS. The exact codes and punctuation (e.g. MD4/ for a slash separator) depend on your DFSORT version; check the manual.

LINES= and Pagination

LINES=n sets the number of lines per page. It is required for HEADER2 and TRAILER2 to repeat—without LINES=, there is no page boundary. The value n usually includes the lines used for header and trailer on that page. Example: LINES=60,BLKCCH2 for 60-line pages with blocking; BLKCCH2 may specify carriage control for the output. Detail records fill the lines between HEADER2 and TRAILER2 on each page.

Complete Example

Sort by student number; output 80-byte records; add a report header with title and date/time, a page header with column titles and page number, and a trailer with record count. Use LINES=9 for a short page (e.g. for illustration):

text
1
2
3
4
5
6
7
8
9
10
SORT FIELDS=(1,5,ZD,A) OUTFIL FNAMES=OUTPUT1,LINES=9,BLKCCH2, HEADER1=(20:'Student Details', 37:'Printed on ',DATE=(MD4/),' AT ',TIME), HEADER2=(/,15:'Class X Students details', 40:'Page',PAGE,53:' on ',58:DATE=(MD4-),4/, 1:'Std num',11:'Std name',30:'Department',45:'Total marks',/, 1:'-------',11:'--------',30:'----------',45:'-----------'), TRAILER1=(1:'Total records: ',COUNT=(M11,LENGTH=10)), OUTREC=(1,80)

HEADER1 runs once at the start. HEADER2 runs at the top of each page (LINES=9). TRAILER1 runs once at the end with the count. OUTREC=(1,80) copies the full record. Define OUTPUT1 in JCL; BLKCCH2 and exact DATE/TIME/PAGE/COUNT syntax depend on your product.

Explain It Like I'm Five

Imagine a worksheet: at the very top you write the title and the date (HEADER1). Then on every new page you write a small title and "Page 1", "Page 2", and the column names (HEADER2). At the very bottom of the whole worksheet you write "Total: 10 rows" (TRAILER1). And at the bottom of each page you might write "Page 1" again (TRAILER2). Generating headers and trailers in DFSORT is telling the sort program to do exactly that: add those lines for you so your report has a title, column names, page numbers, and a total at the end.

Exercises

  1. Write HEADER1 that has the title "Monthly Report" at column 25 and the current date at column 60. Use positioning and DATE= (check your manual for the format code).
  2. What is the purpose of the slash (/) in a HEADER or TRAILER specification?
  3. If you want a record count only at the end of the report (no count on each page), which trailer do you use?
  4. Look up your DFSORT manual: what is the exact syntax for COUNT= in TRAILER1 (keyword and edit mask)?

Quiz

Test Your Knowledge

1. What is the difference between HEADER1 and HEADER2?

  • They are the same
  • HEADER1 appears once at the start of the report; HEADER2 repeats at the top of each page when LINES= is used
  • HEADER2 is for trailers
  • Only HEADER1 supports DATE=

2. How do you position text in a header or trailer?

  • Only at column 1
  • Use position:value syntax, e.g. 20:'Title' places the text at column 20
  • HEADER has no positioning
  • Only TRAILER supports positioning

3. What does TRAILER1 typically contain?

  • Only blanks
  • A report footer: often a record count (COUNT=), grand total, or summary line at the end of the report
  • Page number only
  • Same as HEADER1

4. How do you add the current date and time to a header?

  • Manually
  • Use DATE= and TIME in the HEADER1 or HEADER2 specification, e.g. DATE=(MD4/), TIME with format options
  • Only in JCL
  • OUTREC only

5. When does TRAILER2 appear?

  • Only at the very end
  • At the bottom of each page when LINES= is specified, so it repeats on every page
  • Only with SECTIONS
  • TRAILER2 is the same as TRAILER1