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.
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).
1OUTFIL 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.
When you need more than just formatted detail lines—titles, page headers, footers, totals, or pagination—use OUTFIL. It supports:
| Parameter | Purpose | Note |
|---|---|---|
| BUILD / FIELDS | Define column layout | Field order, constants, nX, edit masks |
| HEADER1 | Report title and top matter | One-time at start; positioning, DATE=, TIME= |
| HEADER2 | Page header | Repeats each page when LINES= is used |
| TRAILER1 | Report trailer / summary | At end; often used for count or grand total |
| TRAILER2 | Page trailer | Repeats at bottom of each page |
| LINES= | Lines per page | Enables pagination and page headers/trailers |
| SECTIONS | Group by key | Section headers/trailers for control breaks |
| REMOVECC | Strip control chars | For online/viewable output |
| NODETAIL | Headers/trailers only | No data lines; summary report |
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:
12HEADER1=(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 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=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=(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 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.
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):
123456SORT 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.
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).
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.
1. What is the main purpose of using OUTFIL BUILD for a report?
2. What does HEADER1 do in OUTFIL?
3. What is LINES= used for in OUTFIL report writing?
4. When would you use REMOVECC in a report OUTFIL?
5. What does NODETAIL do in OUTFIL?