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.
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.
| Type | When it appears | Typical use |
|---|---|---|
| HEADER1 | Once at start of report | Report title, print date/time, opening message |
| HEADER2 | Top of each page (with LINES=) | Column titles, page number, short title |
| TRAILER1 | Once at end of report | Record count, grand total, closing message |
| TRAILER2 | Bottom of each page (with LINES=) | Page number, page footer |
| TRAILER3 | After each section (with SECTIONS) | Section subtotal, section footer |
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:
12HEADER1=(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.
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:
1234HEADER2=(/,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 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:
1TRAILER1=(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 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.
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=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.
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):
12345678910SORT 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.
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.
1. What is the difference between HEADER1 and HEADER2?
2. How do you position text in a header or trailer?
3. What does TRAILER1 typically contain?
4. How do you add the current date and time to a header?
5. When does TRAILER2 appear?