Report writing in DFSORT means using OUTFIL to produce formatted reports—output that looks like a printed or viewable report with a title, column headers, detail lines, and optional footers and page breaks. Unlike a flat data file (one record per line with no headers), a report has structure: a report header (HEADER1) at the start, a page header (HEADER2) that repeats on each page, detail lines built from your data (via BUILD= or OUTREC=), and trailers—a page trailer (TRAILER2) at the bottom of each page and a report trailer (TRAILER1) at the end with counts or totals. When you need control-break style output (e.g. a section per department with a header and subtotal), you use SECTIONS= with HEADER3 and TRAILER3. LINES=n sets the number of lines per page so that page headers and trailers repeat correctly. This page covers the overall report-writing model, how HEADER, TRAILER, SECTIONS, and LINES fit together, and when to use NODETAIL and REMOVECC.
OUTREC can reformat each record (reorder fields, add constants, edit masks) and write the result to SORTOUT. That gives you a single stream of records—no built-in title, no column headers, no page breaks, no footer. For a report, you need more: a title at the top, column headers (often repeated on each page), and optionally a footer with a record count or total. OUTFIL provides HEADER1, HEADER2, TRAILER1, TRAILER2, LINES=, and SECTIONS so you can build a full report in one pass. You still use BUILD= (or OUTREC=) on the same OUTFIL to define the detail line layout; the header and trailer parameters add the extra lines before, after, and around the data.
A typical report has a fixed order of elements. From top to bottom:
| Element | Parameter | Note |
|---|---|---|
| Cover / report header | HEADER1 | Once at start; title, DATE=, TIME= |
| Page header | HEADER2 | Repeats each page when LINES= is used |
| Section header | HEADER3 (in SECTIONS) | Start of each control-break group |
| Detail lines | BUILD= or OUTREC= | One line per record |
| Section trailer | TRAILER3 (in SECTIONS) | Subtotal/footer per section |
| Page trailer | TRAILER2 | Bottom of each page |
| Report trailer | TRAILER1 | End of report; count, grand total |
HEADER1 is usually the report title and print date/time—one or more lines at the very beginning. On some systems it appears on a separate "cover" page. HEADER2 repeats on every page when you specify LINES=n; use it for column titles (e.g. "ID", "Name", "Amount") so each page has a header. The detail lines come from your data, formatted by BUILD= or OUTREC=. TRAILER2 appears at the bottom of each page (e.g. "Page n"). TRAILER1 appears once at the end—often a record count or grand total. When you use SECTIONS, each group gets HEADER3 (e.g. department name) and TRAILER3 (e.g. section subtotal).
LINES=n tells DFSORT how many lines per page to use. Once n lines (typically including header and detail) are written, the next line starts a new page and HEADER2 (and optionally TRAILER2) are written again. If you omit LINES=, many products default to 60 lines per page. So for a 55-line printed page you might code LINES=55. Pagination is what makes HEADER2 and TRAILER2 repeat; without LINES=, there is only one "page" and HEADER2/TRAILER2 appear once at the top and bottom of the whole report.
SECTIONS=(position,length,format,...,HEADER3=(...),TRAILER3=(...)) groups the sorted data by the given key. For each distinct value of that key you get a section. You can define HEADER3 to print at the start of each section (e.g. the key value as a subtitle) and TRAILER3 at the end (e.g. subtotal for that group). So you get classic control-break output: sort by department, then SECTIONS by department, with HEADER3 showing the department name and TRAILER3 showing the department total. SKIP=P in SECTIONS starts each section on a new page; SKIP=nL leaves n blank lines between sections on the same page.
12345SORT FIELDS=(1,5,CH,A) OUTFIL FNAMES=REPORT,LINES=60, HEADER1=(20:'Customer List',37:'Printed on ',DATE=(MD4/),' AT ',TIME), HEADER2=(/,1:'ID',11:'Name',30:'Amount',/,1:'--',11:'----',30:'-----'), BUILD=(1,5,11,25,36,10,PD,M12,LENGTH=12)
HEADER1 prints a title and date/time once at the start. HEADER2 prints column titles and underlines on each page (because LINES=60). Each record is built as ID (bytes 1–5), Name (11–35), and Amount (bytes 36–45 packed, edited with M12). The report is written to the dataset allocated to DD REPORT.
NODETAIL suppresses writing the detail records. Only the header and trailer lines are written. Use it when you want a summary-only report: for example, HEADER1 with a title and TRAILER1 with a grand total or count, and no data lines. Useful for a one-page summary or cover sheet. The sort still runs and any TRAILER1 statistics (e.g. COUNT=, SUM=) are still computed over the data; you just do not write the detail lines.
Mainframe print files often put a carriage control character in the first byte of each record (e.g. 1 for page eject, 0 for single space). When the report is sent to a printer, that byte is interpreted. When the report is viewed online or in an editor, that byte can cause odd display or be mistaken for data. REMOVECC strips the first-byte carriage control from each record so the output is clean for viewing. Use REMOVECC when the report will be displayed or edited; omit it when the output is destined for a printer that expects ASA or machine control.
By default, the first character of HEADER1 or HEADER2 may be used as carriage control (e.g. "1" causes a page eject). So the report header might force a new page before the first data. BLKCCH1 tells DFSORT to replace the first character of the first line of HEADER1 with a blank so that no page eject occurs—the report header can stay on the same page as the first data. BLKCCH2 does the same for the first line of HEADER2. Use these when you want the header on the same page as the data instead of on a separate sheet.
You can produce both a report and a data file from one sort step. Use one OUTFIL with FNAMES=REPORT and HEADER1/HEADER2/TRAILER1/LINES= for the report, and another OUTFIL with FNAMES=DATA (and no header/trailer) for the raw or reformatted records. Or write the main output to SORTOUT and use OUTFIL only for the report. Each output is independent.
Imagine a school report: the first page has a big title and the date (that's HEADER1). Then every new page has a small title at the top like "Student List" and column names "Name", "Grade" (that's HEADER2). The middle of each page is the list of students (that's the detail). At the bottom of each page it says "Page 2" (that's TRAILER2). At the very end of the whole report it says "Total: 100 students" (that's TRAILER1). Report writing in DFSORT is telling the sort program how to draw that whole thing—title, headers, lines, and footers—so you get a nice report instead of just a pile of lines.
1. What is the main reason to use OUTFIL for report writing instead of OUTREC only?
2. What does SECTIONS do in an OUTFIL report?
3. When would you use NODETAIL on a report OUTFIL?
4. What is the default number of lines per page if you do not specify LINES=?
5. What is REMOVECC used for in report output?