Headers and trailers in OUTFIL are the fixed lines that frame your report: a report header (HEADER1) at the start, a page header (HEADER2) at the top of each page, a report trailer (TRAILER1) at the end, and a page trailer (TRAILER2) at the bottom of each page. When you use SECTIONS= for control-break groups, you add a section header (HEADER3) and section trailer (TRAILER3) for each group. In each header or trailer you can use positioning (e.g. 20:\'Title\' to start text at column 20), DATE= and TIME for print date and time, PAGE for the current page number, and COUNT= or totals in trailers. Optional parameters BLKCCH1, BLKCCH2, and BLKCCT1 control carriage control so that headers and the report trailer do not force unwanted page ejects. This page is a deep dive on HEADER1/2/3 and TRAILER1/2/3 in the OUTFIL context: syntax, positioning, multi-line, and when each is used.
OUTFIL supports three headers and three trailers. Each appears at a different point in the report:
| Type | When it appears | Typical content |
|---|---|---|
| HEADER1 | Once at start of report | Report title, DATE=, TIME=, cover info |
| HEADER2 | Top of each page (with LINES=) | Column titles, PAGE, short title |
| HEADER3 | Start of each section (with SECTIONS) | Section key, section subtitle |
| TRAILER1 | Once at end of report | 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 count |
HEADER1 is often a cover or title page: report name, run date, run time. HEADER2 repeats on every page when you specify LINES=n—use it for column titles and page number. HEADER3 is inside SECTIONS=: it prints at the start of each control-break group (e.g. department name). TRAILER1 is the report footer: grand total, record count, or closing message. TRAILER2 repeats at the bottom of each page (e.g. "Page n"). TRAILER3 is inside SECTIONS: subtotal or count after each group.
To place text at a specific column, use position:\'text\' or position:constant. For example 20:\'Report Title\' starts "Report Title" at column 20. You can mix multiple items on one line: 1:\'ID\',11:\'Name\',41:\'Amount\' puts three labels at columns 1, 11, and 41. To start a new line, use /. Example: HEADER1=(20:\'Title\',/,1:\'Subtitle\') gives two lines. Do not start a header or trailer element with C\' for a constant in some products—use a quoted string or position:literal; check your manual.
DATE=(format) inserts the current date. Common formats (product-dependent) include MD4 or MD4/ for MM/DD/YYYY, MD4- for MM-DD-YYYY, Y2Y for YYYY, and others. TIME inserts the current time (often HH:MM:SS). Example: HEADER1=(37:\'Printed on \',DATE=(MD4/),\' AT \',TIME) might produce "Printed on 02/14/2025 AT 14:30:00". Use these in HEADER1 for run stamp and in HEADER2 for "Page n on date".
PAGE (or product equivalent) inserts the current page number. Use it in HEADER2= so each page shows its number—e.g. 40:\'Page \',PAGE,53:\' on \',58:DATE=(MD4-). Because HEADER2 repeats on each page, PAGE will be 1, 2, 3, and so on. Some products support a total page count for "Page 2 of 10"; see your manual.
In TRAILER1= (or TRAILER3= for section totals), you can include a record count or numeric total. Syntax is product-specific. Often something like COUNT=(M10,LENGTH=10) or COUNT=(M11,LENGTH=8) formats the number of records written. For a sum of a numeric field, SUM= or SUBTOTAL= with position, length, format, and edit mask may be used. For section-level totals, use the same in TRAILER3= inside SECTIONS. Check your DFSORT manual for exact COUNT=, SUM=, MIN=, MAX=, AVG= syntax in trailers.
On systems that use the first byte of a record for carriage control (e.g. 1 = new page, 0 = single space), the first character of a header or trailer line can trigger a page eject. BLKCCH1 tells DFSORT to replace the first character of the first line of HEADER1 with a blank so the report header does not force a new page—the header can appear on the same page as the first data. BLKCCH2 does the same for the first line of HEADER2. BLKCCT1 does the same for the first line of TRAILER1 so the report trailer does not force a new page before or after it. Use these when you want to avoid extra blank pages.
12345OUTFIL FNAMES=REPORT,LINES=60, HEADER1=(20:'Sales Report',37:'Printed on ',DATE=(MD4/),' AT ',TIME), HEADER2=(/,1:'Region',15:'Amount',/,1:'----------',15:'------------'), BUILD=(1,10,15,12,PD,M12,LENGTH=12), TRAILER1=(2/,5:'Total records: ',COUNT=(M11,LENGTH=8))
HEADER1 has a title and print date/time. HEADER2 has column titles and an underline on each page. TRAILER1 has two blank lines (2/) then "Total records: " and a count formatted with M11. Exact COUNT= syntax may vary by product.
Use / to separate lines. For example HEADER1=(20:\'Main Title\',/,15:\'Subtitle\',/,5:DATE=(MD4-)) produces three lines. You can use n/ or n in some products to insert blank lines: at the start or end, n may mean n blank lines; in the middle, n may mean n-1 blank lines. Check your manual. Multi-line TRAILER1 is common for a summary block (e.g. count, then min, then max, then avg on separate lines).
Headers are the lines at the top of your report: the first page has a big title (HEADER1), and every page has a small title at the top like "Page 2" (HEADER2). Trailers are the lines at the bottom: at the very end you might say "Total: 100 records" (TRAILER1), and on every page you might put "Page 2" at the bottom (TRAILER2). So headers and trailers are the "frames"—the title and footer—and the middle is your data. HEADER3 and TRAILER3 are like a small title and small footer for each group (e.g. each department) when you use sections.
1. Where does TRAILER3 appear in an OUTFIL report?
2. How do you position text at column 25 in a header or trailer?
3. What do BLKCCH1 and BLKCCH2 do?
4. What is the difference between TRAILER1 and TRAILER2?
5. How do you add the current date and time to HEADER1?