MainframeMaster

Building Reports with DFSORT

Building reports with DFSORT means using OUTREC or OUTFIL to produce formatted, human-readable output—aligned columns, titles, page headers and footers, and optional totals or counts. You use BUILD= or FIELDS= to define the report layout (which fields, in what order, with constants and edit masks), and when you need headers, trailers, and pagination you use OUTFIL with HEADER1, HEADER2, TRAILER1, TRAILER2, LINES=, and optionally SECTIONS for control-break style reports. REMOVECC strips carriage control for online viewing; NODETAIL writes only headers and trailers for summary reports. This page covers how to lay out report columns, add headers and trailers, paginate, and choose between OUTREC and OUTFIL for report-style output.

Report Generation
Progress0 of 0 lessons

Report Layout with BUILD or FIELDS

The core of a report is the detail line—one line per record (or per group). You define it with OUTREC FIELDS= or OUTFIL BUILD=. Specify the fields you want, in order, with nX for spaces between columns, C'...' for constants, and edit masks (or predefined masks like M12) for numeric columns so amounts show with commas and decimals. Example: id (1–10), 5 spaces, name (11–30), 5 spaces, amount (31–34, PD, M12).

text
1
OUTFIL FNAMES=REPORT,BUILD=(1,10,5X,11,20,5X,31,4,PD,M12)

The output has fixed columns: id, then blanks, then name, then blanks, then the amount formatted with the M12 mask. Adjust positions and lengths to match your input record; the total length of the BUILD output determines the report line length. For SORTOUT you would use OUTREC with the same FIELDS= or BUILD= logic if you are not using OUTFIL.

Report Features in OUTFIL

When you need more than just formatted detail lines—titles, page headers, footers, totals, or pagination—use OUTFIL. It supports:

OUTFIL report-related parameters
ParameterPurposeNote
BUILD / FIELDSDefine column layoutField order, constants, nX, edit masks
HEADER1Report title and top matterOne-time at start; positioning, DATE=, TIME=
HEADER2Page headerRepeats each page when LINES= is used
TRAILER1Report trailer / summaryAt end; often used for count or grand total
TRAILER2Page trailerRepeats at bottom of each page
LINES=Lines per pageEnables pagination and page headers/trailers
SECTIONSGroup by keySection headers/trailers for control breaks
REMOVECCStrip control charsFor online/viewable output
NODETAILHeaders/trailers onlyNo data lines; summary report

HEADER1 and HEADER2

HEADER1 creates the main report header—one or more lines at the very beginning of the report. You can use positioning syntax (e.g. 20:'Report Title' to place text at column 20) and often DATE= and TIME= for print date and time. Use / to separate multiple lines. Example:

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

HEADER2 is the page header: it repeats at the top of each page when you specify LINES=n for pagination. Use it for column titles or a short title that should appear on every page.

TRAILER1 and TRAILER2

TRAILER1 is the report trailer—typically one or more lines at the end of the report. It is often used for a record count or grand total (e.g. COUNT= or total fields); the exact syntax is product-specific (see "Generating headers/trailers" and "Report totals"). TRAILER2 is the page trailer: it repeats at the bottom of each page when LINES= is used. Use it for "Page n" or a short footer.

LINES= and Pagination

LINES=n sets the number of lines per page. Once set, HEADER2 and TRAILER2 (if specified) repeat on each page. The value n usually includes the lines used for header and trailer on that page, so the number of detail lines per page is less than n. Check your manual for exact behavior. Example: LINES=60 for 60-line pages with a page header and optional page trailer.

SECTIONS for Control Breaks

SECTIONS=(start,length,FORMAT=type) groups records by a key (e.g. department code at 1,2). With SECTIONS you can add section-level headers and trailers—for example, a subtitle and subtotal after each group. That gives you control-break style reports: a header and/or trailer for each value of the section key. Details are in the "Control break reporting" and "Subtotals" topics.

REMOVECC and NODETAIL

REMOVECC removes the first-byte carriage control (e.g. ASA) from each output record. Use it when the report will be viewed online or in an editor; leave it off for traditional print files so the printer can use the control byte. NODETAIL suppresses writing detail records: only the header and trailer lines (and any section headers/trailers) are written. Use it for summary-only output—for example, just a title and a TRAILER1 with a count.

Complete Example: Simple Report with Header and Trailer

Sort by name; build a detail line with id, name, amount; add a report header and a trailer with a count (syntax may vary by product):

text
1
2
3
4
5
6
SORT FIELDS=(11,20,CH,A) OUTFIL FNAMES=REPORT, BUILD=(1,10,5X,11,20,5X,31,4,PD,M12), HEADER1=(1:'ID',10:'Name',35:'Amount',/), TRAILER1=(1:'Total records: ',COUNT=(M11,LENGTH=10)), REMOVECC

HEADER1 gives a title line with column labels. BUILD formats each record. TRAILER1 adds a line with a record count (COUNT= syntax is product-dependent). REMOVECC strips control characters for viewing. Define the REPORT DD in JCL.

OUTREC vs OUTFIL for Reports

Use OUTREC when you only need formatted detail lines going to SORTOUT—no headers, trailers, or pagination. Use OUTFIL when you need HEADER1/HEADER2, TRAILER1/TRAILER2, LINES=, SECTIONS, REMOVECC, or NODETAIL, or when you want the report to go to a different dataset than SORTOUT (e.g. FNAMES=REPORT while SORTOUT is used for something else).

Explain It Like I'm Five

Building a report is like making a chart: first you decide what goes on each row (the detail line—name, number, etc.). Then you add a title at the top (HEADER1) and maybe a line at the bottom that says how many rows there are (TRAILER1). If the chart is long, you can say "only 50 rows per page" (LINES=50) and put a small title on every page (HEADER2). DFSORT does all of that: you tell it the columns (BUILD), the title (HEADER1), the bottom line (TRAILER1), and it writes the report for you.

Exercises

  1. Write an OUTFIL BUILD= that produces a detail line: bytes 1–8 (id), 10 spaces, bytes 20–45 (name), 5 spaces, bytes 50–53 (packed amount) with M12. What is the approximate output length?
  2. When would you use HEADER2 instead of only HEADER1?
  3. What is the effect of NODETAIL on the output file?
  4. Look up your product manual: how do you specify a record count in TRAILER1 (e.g. COUNT= or similar)?

Quiz

Test Your Knowledge

1. What is the main purpose of using OUTFIL BUILD for a report?

  • To sort faster
  • To arrange fields into fixed columns, add constants and blanks, and apply edit masks so the output looks like a readable report
  • To merge files
  • To omit records

2. What does HEADER1 do in OUTFIL?

  • Sorts by header
  • Creates a header line (or lines) that appear at the beginning of the report; can include fixed text, positioning, date, time
  • Removes headers
  • Only for VB files

3. What is LINES= used for in OUTFIL report writing?

  • Record length
  • Pagination: specifies how many lines per page so that HEADER2 and TRAILER2 can repeat on each page
  • Number of output files
  • Sort key length

4. When would you use REMOVECC in a report OUTFIL?

  • To add carriage control
  • To remove ANSI carriage control characters from the first byte of each record so the output can be viewed online or in editors without control characters
  • Only for SORT
  • To increase speed

5. What does NODETAIL do in OUTFIL?

  • Removes headers
  • Suppresses writing the actual data (detail) records; only headers and trailers are written, useful for summary-only reports
  • Doubles records
  • Sorts in reverse