MainframeMaster

Headers and Trailers in OUTFIL

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 Advanced
Progress0 of 0 lessons

The Six Header and Trailer Types

OUTFIL supports three headers and three trailers. Each appears at a different point in the report:

HEADER and TRAILER types in OUTFIL
TypeWhen it appearsTypical content
HEADER1Once at start of reportReport title, DATE=, TIME=, cover info
HEADER2Top of each page (with LINES=)Column titles, PAGE, short title
HEADER3Start of each section (with SECTIONS)Section key, section subtitle
TRAILER1Once at end of reportCOUNT=, grand total, closing message
TRAILER2Bottom of each page (with LINES=)Page number, page footer
TRAILER3After 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.

Positioning: position:\'text\'

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= and TIME

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 in HEADER2

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.

COUNT= and Totals in Trailers

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.

BLKCCH1, BLKCCH2, BLKCCT1

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.

Example: HEADER1 and TRAILER1 with Date and Count

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

Multi-Line Headers and Trailers

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).

Explain It Like I'm Five

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.

Exercises

  1. Write HEADER1 with a title at column 25 and the current date at column 60. Use / and a second line with TIME at column 60.
  2. What is the difference between TRAILER2 and TRAILER3? When would you use each?
  3. When would you specify BLKCCH2? What problem does it solve?
  4. Look up your DFSORT manual for the exact syntax of COUNT= in TRAILER1 (edit mask and LENGTH).

Quiz

Test Your Knowledge

1. Where does TRAILER3 appear in an OUTFIL report?

  • Only at the very end of the report
  • After each section when SECTIONS= is used—e.g. a subtotal line after each control-break group
  • At the bottom of each page
  • Only with HEADER1

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

  • Only column 1 is supported
  • Use position:value syntax, e.g. 25:'Title' places the text starting at column 25
  • HEADER has no positioning
  • Use BUILD= only

3. What do BLKCCH1 and BLKCCH2 do?

  • Block the report
  • Replace the first character of the first line of HEADER1 (BLKCCH1) or HEADER2 (BLKCCH2) with a blank to avoid page eject
  • Add carriage control
  • Only for TRAILER

4. What is the difference between TRAILER1 and TRAILER2?

  • They are the same
  • TRAILER1 appears once at the end of the report; TRAILER2 repeats at the bottom of each page when LINES= is used
  • TRAILER2 is only for SECTIONS
  • TRAILER1 is for page count only

5. How do you add the current date and time to HEADER1?

  • Only in JCL
  • Use DATE= and TIME in the HEADER1= specification—e.g. DATE=(MD4/), ' AT ', TIME
  • Only in OUTREC
  • DATE= is only for TRAILER