Using DFSORT as a report writer means producing formatted reports—output with a title, column headers, detail lines, and optional footers and page breaks—directly from a DFSORT step, without a separate COBOL or other report program. DFSORT can sort or merge the data and then use OUTFIL to add HEADER1 (report title), HEADER2 (page header), TRAILER1 (report trailer), TRAILER2 (page trailer), LINES= (pagination), and SECTIONS for control-break style section headers and trailers. The detail line is defined with BUILD= or OUTREC=—field positions, constants, and edit masks. This page explains when DFSORT is a good fit as a report writer, what it can and cannot do, and how the report model fits together. For detailed syntax, see Report writing, Building reports, Page numbering, and Headers/trailers.
DFSORT is a good choice when the report is driven by sorted or merged data and has a predictable layout: a title at the top, column headers (often repeated on each page), one detail line per record (or per group), and optional footers with record counts or totals. You can express that with control statements: SORT (or MERGE), then OUTFIL with BUILD= for the detail line and HEADER1, HEADER2, TRAILER1, TRAILER2, LINES=, and optionally SECTIONS. No separate program is needed.
DFSORT is not a full programming language. Complex row-by-row logic—multiple nested conditions, lookups to other files, or heavy computation per line—is better handled by a COBOL or other report program. Use DFSORT when the report can be described as "sort (or merge), then output with fixed headers, detail layout, and trailers."
A typical report has these elements. DFSORT OUTFIL supports them as follows:
| Element | OUTFIL parameter | Notes |
|---|---|---|
| Report title / cover | HEADER1 | Once at the start; can include fixed text, DATE=, TIME=. |
| Page header | HEADER2 | Repeats at top of each page when LINES= is used (e.g. column titles). |
| Detail lines | BUILD= or OUTREC= | One line per record; field positions, constants, edit masks. |
| Report trailer | TRAILER1 | Once at end; record count, grand total. |
| Page trailer | TRAILER2 | Repeats at bottom of each page. |
| Pagination | LINES=n | Lines per page; enables HEADER2/TRAILER2 to repeat. |
| Section header/trailer | SECTIONS with HEADER3/TRAILER3 | Control-break groups; header and subtotal per section. |
In one DFSORT step you typically: (1) read from SORTIN; (2) optionally apply INREC to reformat or INCLUDE/OMIT to filter; (3) SORT or MERGE; (4) write to SORTOUT (optionally with OUTREC) and/or to an OUTFIL report. The report OUTFIL uses BUILD= to define the detail line and adds HEADER1, HEADER2, TRAILER1, TRAILER2, and LINES= as needed. If the report has control breaks (e.g. by department), you sort by the control field and use SECTIONS= with HEADER3 and TRAILER3 for each section.
1234567SORT FIELDS=(1,10,CH,A) OUTFIL FNAMES=REPORT, BUILD=(1,10,15X,11,40,45X,41,4,PD,M12), HEADER1=(1:'SALES REPORT',60:DATE), HEADER2=(1:'ID',16:'NAME',46:'AMOUNT'), TRAILER1=(1:'TOTAL RECORDS:',COUNT=(M10,LENGTH=10)), LINES=55
Data is sorted by bytes 1–10. The report has a title and date in HEADER1, column headers in HEADER2, detail lines built from positions 1–10, 11–40, and 41–44 (packed, edited with M12), and a trailer with a record count. LINES=55 gives 55 lines per page so HEADER2 repeats. Exact syntax for COUNT= and DATE= is product-dependent; see your manual.
Capabilities: Sort or merge; filter (INCLUDE/OMIT); reformat (INREC, OUTREC); build report with title, page headers, detail lines with edit masks, page and report trailers, pagination, and control-break sections. You can produce both a data file (SORTOUT) and a report (OUTFIL FNAMES=) in one step. REMOVECC strips carriage control for online viewing; NODETAIL writes only headers and trailers for summary reports.
Limitations: No arbitrary program logic per record. Complex conditionals, multi-file lookups, or highly variable line layout are better done in a program. Subtotals and totals in TRAILER1/TRAILER3 depend on product-supported options (e.g. SUM=, COUNT=). For very simple "sorted listing with a title," OUTREC and a single header/trailer line (e.g. via OUTFIL) may be enough; for full pagination and control breaks, use the full OUTFIL report features.
Imagine you have a list of toys and you want to make a nice report: a title at the top ("My Toys"), column names (Name, Color, Size), then one line per toy, and at the bottom "Total: 10 toys." DFSORT can do that: it sorts the list (if you want), then writes the title, the column names, each line of data, and the total—all in one step. For fancier reports (like "every time the color changes, print a subtitle and a small total"), DFSORT can do that too with sections. When the report gets too fancy (different rules for every line), a person writing a program is better than letting the sort tool do it.
1. When is DFSORT a good choice for producing a report?
2. What is the main limitation of DFSORT as a report writer?
3. Which OUTFIL parameters are used for the overall report structure?
4. Can you produce both a data file and a report from the same DFSORT step?
5. What is the typical "report writer" flow in a DFSORT step?