MainframeMaster

Headers and Trailers in Reports

In DFSORT report output, headers and trailers are the lines that frame your data: a report header (HEADER1) at the very start—often the report title and run date/time—a page header (HEADER2) that repeats on each page—typically column titles and page number—and trailers: a report trailer (TRAILER1) at the end with record count or grand total, and a page trailer (TRAILER2) at the bottom of each page. When you use SECTIONS= for control breaks, you also get a section header (HEADER3) and section trailer (TRAILER3) for each group. This page focuses on what to put in each type of header and trailer (titles, dates, page numbers, counts, totals), positioning and multi-line content (using the slash /), and options like BLKCCH1 so the report prints without unwanted page ejects. For full OUTFIL syntax, see Headers and trailers (OUTFIL).

Report Generation
Progress0 of 0 lessons

What Goes Where

A report has a clear structure. Knowing where each piece of text goes helps you choose the right parameter:

Header and trailer usage in reports
ParameterWhen it appearsTypical content
HEADER1Once at the very beginningReport title, run date (DATE=), run time (TIME=), company or department name.
HEADER2Top of each page (when LINES= is used)Column titles, short title, page number (PAGE).
HEADER3Start of each section (when SECTIONS= is used)Section key (e.g. department name), section subtitle.
TRAILER1Once at the very endRecord count (COUNT=), grand total, "END OF REPORT."
TRAILER2Bottom of each pagePage number (PAGE), "Continued", or short footer.
TRAILER3End of each sectionSection subtotal, section record count.

Report Header (HEADER1): Title and Run Information

HEADER1 is the first thing the reader sees. Use it for the report title (e.g. "MONTHLY SALES REPORT"), the run date and time (DATE= and TIME=), and any one-time text (e.g. department or parameter). You can use positioning to place text at specific columns—e.g. 1:'Title' and 60:DATE to put the date on the right side of an 80-column line.

text
1
HEADER1=(1:'SALES REPORT',/,1:'Run date: ',DATE=(MD4-),25:'Run time: ',TIME)

The first line is "SALES REPORT"; the second line (after /) has "Run date: ", the date in MM-DD-YYYY form, and "Run time: " plus the time. DATE= and TIME= formats are product-dependent (e.g. MD4, MD4-, Y2Y for date; check your manual).

Page Header (HEADER2): Column Titles and Page Number

HEADER2 repeats on every page. Use it for column titles (e.g. "ID", "Name", "Amount") so each page has a header line that matches the detail columns. You can also put the page number (PAGE) in HEADER2—e.g. "Page ", PAGE at a fixed position. Keep HEADER2 short so it does not use too many of the LINES= per page; one or two lines is typical.

text
1
HEADER2=(1:'ID',11:'Name',41:'Amount',60:'Page ',PAGE)

One line: column titles at 1, 11, 41, and "Page " plus PAGE at 60. So every page has the same header with the correct page number.

Report Trailer (TRAILER1): Count and Grand Total

TRAILER1 appears once at the end of the report. Use it for the record count (COUNT= or product equivalent), a grand total (if supported), and any closing text (e.g. "END OF REPORT"). The count or total is computed after all detail records are written, so TRAILER1 is the right place for report-level summary information.

text
1
TRAILER1=(1:'Total records: ',COUNT=(M10,LENGTH=10),/,1:'*** END OF REPORT ***')

First line: "Total records: " and the count (formatted with M10, length 10). Second line: "*** END OF REPORT ***". Exact COUNT= syntax (M10, LENGTH=, etc.) is product-dependent; see your DFSORT manual.

Page Trailer (TRAILER2) and Section Trailer (TRAILER3)

TRAILER2 is at the bottom of each page. Use it for the page number (if you prefer it at the bottom), "Continued on next page", or a short footer. TRAILER3 is used with SECTIONS=: it appears after each control-break group. Put section-level information there—e.g. subtotal for that section or "Section end." So TRAILER2 is per-page; TRAILER3 is per-section.

Multi-Line Headers and Trailers: The Slash (/)

In HEADER1=, HEADER2=, TRAILER1=, and TRAILER2=, the slash (/) starts a new line. So you can build multi-line titles and footers. Example:

text
1
HEADER1=(1:'ACME CORPORATION',/,1:'SALES REPORT',/,1:'Period: ',50:DATE)

Three lines: "ACME CORPORATION", then "SALES REPORT", then "Period: " and the date at position 50. Use as many lines as you need; each / begins a new line.

Positioning: Where Text Appears

You control where text appears using position:content. For example 1:'Title' puts "Title" at column 1; 60:DATE puts the date starting at column 60 (right side of an 80-column line). You can mix positioned and non-positioned items; order determines the default position when not specified. So you can left-align the title and right-align the date in the same header line.

BLKCCH1 and BLKCCH2: Avoiding Unwanted Page Ejects

On some systems, the first byte of each line is used for carriage control (e.g. "1" = new page, "0" = space one line). If HEADER1 or HEADER2 starts with a control character that means "eject page," you may get a blank page before or after the header. BLKCCH1 tells DFSORT to replace the first character of the first line of HEADER1 with a blank so the report title does not force a page eject. BLKCCH2 does the same for HEADER2. Use them when the report is going to a printer or dataset that interprets carriage control and you want the header on the same page as the data.

Section Headers and Trailers (HEADER3, TRAILER3)

When you use SECTIONS=(position,length,...), records are grouped (e.g. by department). HEADER3 is output at the start of each section—e.g. the department name or a subtitle. TRAILER3 is output at the end of each section—e.g. a subtotal or "Section total." So you get a header and trailer around each group for classic control-break reporting. See Control break reporting and Report totals for subtotal/total syntax.

Explain It Like I'm Five

Think of a report like a letter. The first line might say "SALES REPORT" and "January 2025"—that's the report header (HEADER1). Every new page has a line at the top that says "ID, Name, Amount" and "Page 2"—that's the page header (HEADER2). At the very end you write "Total: 100 records" and "The End"—that's the report trailer (TRAILER1). DFSORT lets you define exactly what goes in those top and bottom lines so your report looks finished and professional.

Exercises

  1. You want a two-line report title: "QUARTERLY REPORT" on line 1 and "Run: " plus date on line 2. Write the HEADER1= using /.
  2. Where do you put the grand total of a numeric field—HEADER1, TRAILER1, or TRAILER2? Why?
  3. When would you use BLKCCH1? What problem does it solve?

Quiz

Test Your Knowledge

1. What is the best use of HEADER1 in a report?

  • Page number only
  • Report title, run date/time, and any one-time text at the very beginning of the report
  • Column headers only
  • Only for SECTIONS

2. Where do you put the record count or grand total in a report?

  • In HEADER2
  • In TRAILER1—the report trailer that appears once at the end of the report
  • In BUILD= only
  • Only in SECTIONS

3. How do you get multiple lines in a header or trailer?

  • Use multiple OUTFIL statements
  • Use the slash (/) to separate lines—e.g. HEADER1=('Line 1',/,'Line 2')
  • Only one line per header
  • Use LINES= only

4. What is the difference between TRAILER2 and TRAILER3?

  • They are the same
  • TRAILER2 is the page trailer (bottom of each page); TRAILER3 is the section trailer (after each control-break group when SECTIONS= is used)
  • TRAILER3 is only for the first page
  • TRAILER2 is only for report total

5. Why would you use BLKCCH1 in a report?

  • To add carriage control
  • To replace the first character of the first line of HEADER1 with a blank so the report title does not force a page eject—the header can appear on the same page as the first data
  • To block the report
  • Only for TRAILER1