MainframeMaster

DFSORT as Report Writer

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.

Report Generation
Progress0 of 0 lessons

When to Use DFSORT for Reports

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."

The Report Model: What DFSORT Can Produce

A typical report has these elements. DFSORT OUTFIL supports them as follows:

Report elements in DFSORT OUTFIL
ElementOUTFIL parameterNotes
Report title / coverHEADER1Once at the start; can include fixed text, DATE=, TIME=.
Page headerHEADER2Repeats at top of each page when LINES= is used (e.g. column titles).
Detail linesBUILD= or OUTREC=One line per record; field positions, constants, edit masks.
Report trailerTRAILER1Once at end; record count, grand total.
Page trailerTRAILER2Repeats at bottom of each page.
PaginationLINES=nLines per page; enables HEADER2/TRAILER2 to repeat.
Section header/trailerSECTIONS with HEADER3/TRAILER3Control-break groups; header and subtotal per section.

Typical Flow: Sort Then Report

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.

text
1
2
3
4
5
6
7
SORT 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 and Limitations

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.

Relation to Other Tutorials

  • Report writing and Building reports: Detailed OUTFIL syntax—HEADER1/2, TRAILER1/2/3, SECTIONS, LINES, BUILD, NODETAIL, REMOVECC.
  • Page numbering: How to add page numbers to report output.
  • Headers/trailers (reports): Deeper treatment of header and trailer content and positioning.
  • Control break reporting and Subtotals: Section headers/trailers and subtotal/total options.

Explain It Like I'm Five

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.

Exercises

  1. You have a sorted file and want a one-page "summary" with only a title and a record count—no detail lines. Which OUTFIL option do you use?
  2. What is the difference between HEADER1 and HEADER2 in terms of when they appear?
  3. When would you choose a COBOL report program over DFSORT for report output?

Quiz

Test Your Knowledge

1. When is DFSORT a good choice for producing a report?

  • Only when no sort is needed
  • When the report is driven by sorted or merged data, with fixed layout: title, column headers, detail lines, optional page/section footers and pagination
  • Only for binary files
  • When you need complex conditional logic in every line

2. What is the main limitation of DFSORT as a report writer?

  • It cannot sort
  • It has no header support
  • Complex row-by-row logic (e.g. multi-level conditionals, lookups, or heavy computation per line) is harder or impossible; a program is better for that
  • It cannot use OUTFIL

3. Which OUTFIL parameters are used for the overall report structure?

  • Only BUILD=
  • HEADER1 (report title), HEADER2 (page header), TRAILER1 (report trailer), TRAILER2 (page trailer), LINES= (pagination), SECTIONS (control breaks)
  • Only SORT FIELDS=
  • INCLUDE only

4. Can you produce both a data file and a report from the same DFSORT step?

  • No; only one output
  • Yes; SORTOUT can hold the raw or reformatted data, and one or more OUTFIL FNAMES= can hold the report(s) with headers/trailers
  • Only with two steps
  • Only if they are identical

5. What is the typical "report writer" flow in a DFSORT step?

  • INCLUDE only
  • Optional INREC/INCLUDE → SORT/MERGE → OUTFIL with BUILD= for detail lines, HEADER1/2, TRAILER1/2, LINES=, and optionally SECTIONS for control breaks
  • OUTREC only with no OUTFIL
  • SUM only