Control break reporting in DFSORT means dividing a sorted dataset into groups (sections) based on one or more key fields and printing a section header at the start of each group and a section trailer (e.g. subtotal or count) at the end of each group. For example, records sorted by department might show a header line "Department: SALES" and a trailer line "Count: 25, Total: 15000" after the last record for that department. You achieve this with the SECTIONS= parameter on OUTFIL, together with HEADER3 (section header) and TRAILER3 (section trailer). The data must be sorted by the section key first so that all records in a group are adjacent. This page explains how control breaks work, how to define single-level and multi-level sections, and how to use SKIP=P (new page per section) or SKIP=nL (blank lines between sections). For report headers and trailers in general, see Headers/trailers (reports); for subtotals and totals, see Subtotals and Report totals.
A control break occurs when the value of a key field changes from one record to the next. In a file sorted by department, a break happens when you move from the last record of department A to the first record of department B. In traditional report programming, you would read records, compare the key to the previous key, and when it changes you would print a subtotal (or other summary) for the previous group and optionally a header for the new group. In DFSORT, SECTIONS= does this for you: you define which field(s) form the section key, and DFSORT outputs HEADER3 at the start of each new section and TRAILER3 at the end of each section. The result is a report with clear grouping and per-group summaries.
SECTIONS= assumes that records with the same section key are consecutive. When the key value changes, DFSORT treats that as the start of a new section: it writes TRAILER3 for the previous section and HEADER3 for the new one. If the data were not sorted by that key, the same key value could appear in many separate chunks (e.g. department SALES scattered throughout the file). You would get many small "sections" with incorrect subtotals. So the rule is: sort (or merge) by the same field(s) you use in SECTIONS=. For example, if the section key is positions 30–34 (department code), use SORT FIELDS=(30,5,CH,A) so all records for the same department are together.
The SECTIONS= parameter specifies the section key (starting position and length), optional skip behavior, and the section header and trailer. Format (product-dependent) is typically:
1234567OUTFIL FNAMES=report_dd, SECTIONS=(section_key_start,section_key_length, SKIP=P or SKIP=nL, HEADER3=(...), TRAILER3=(...)), OUTREC=(...) or BUILD=(...)
section_key_start and section_key_length define the field that identifies each group (e.g. 30,5 for a 5-byte department code at position 30). SKIP=P starts each section on a new page; SKIP=nL leaves n blank lines between sections on the same page. HEADER3 and TRAILER3 use the same kind of content as other headers and trailers: literals, positioning, field references, COUNT=, TOTAL=, MIN=, MAX=, AVG=, and the slash (/) for new lines. The section key value can be referenced by position and length in HEADER3 or TRAILER3 (e.g. 30,5 to print the department code).
Assume input records have department at positions 30–34 (5 bytes) and total marks at 45–47 (3 bytes, zoned decimal). Sort by department, then use SECTIONS= with that key. HEADER3 prints the department name at the start of each section; TRAILER3 prints count, min, max, and average for that section.
123456789101112SORT FIELDS=(30,5,CH,A) OUTFIL FNAMES=OUTPUT1, SECTIONS=(30,5,SKIP=P, HEADER3=(3:X,/, 3:'Department: ',30,5,/,X,/, 1:'Std num',11:'Std name',30:'Department',45:'Total marks',/, 1:'-------',11:'--------',30:'----------',45:'-----------'), TRAILER3=(2/, 5:'Max Marks = ',MAX=(45,3,ZD,M12,LENGTH=10),/, 5:'Min Marks = ',MIN=(45,3,ZD,M12,LENGTH=10),/, 5:'Avg Marks = ',AVG=(45,3,ZD,M12,LENGTH=10))), OUTREC=(1,80)
Each time the value in 30,5 changes, TRAILER3 is written (the previous section's min/max/avg), then HEADER3 is written for the new section (department label and column headers). SKIP=P forces each department onto a new page. OUTREC=(1,80) defines the detail line layout. Format names (M12, etc.) and exact TRAILER3 syntax may vary by product; see your DFSORT manual.
These options control how sections are separated in the report:
| Option | Effect |
|---|---|
| SKIP=P | Start each section on a new page. Use when each group (e.g. each department) should appear on its own page. |
| SKIP=nL | Keep sections on the same page when possible; insert n blank lines between sections. Use when you want multiple sections on one page with visual separation. |
SKIP=P is typical for formal reports where each major group (region, department) gets a full page. SKIP=2L or SKIP=3L is useful when sections are short and you want to save paper or fit more groups on one page.
HEADER3 is printed once at the start of each section. Common uses:
You can reference the section key in HEADER3 by specifying its position and length (e.g. 30,5). DFSORT will insert the actual value (e.g. SALES, ACCT) for that section.
TRAILER3 is printed once at the end of each section—after the last detail record of the group. Typical content:
Syntax for COUNT=, TOTAL=, MIN=, MAX=, AVG= is product-dependent (e.g. field position, length, format, output length). Check your manual. The idea is the same: TRAILER3 is evaluated for the set of records in the current section only.
You can define more than one level of break. For example, break by region first, then by department within region. Data must be sorted by both keys in order (e.g. SORT FIELDS=(1,6,CH,A,30,5,CH,A)). Then SECTIONS= can specify multiple keys; each level typically has its own HEADER and TRAILER (e.g. HEADER3/TRAILER3 for region, HEADER4/TRAILER4 for department). When the region changes, you get TRAILER3 and TRAILER4 for the previous department, then TRAILER3 for the previous region, then HEADER3 for the new region and HEADER4 for the first department in that region. Exact ordering and level numbers depend on the product; see your DFSORT or ICETOOL documentation for multi-level SECTIONS= syntax.
In practice, you specify something like SECTIONS=(region_start,region_len, HEADER3=..., TRAILER3=..., department_start,department_len, HEADER4=..., TRAILER4=...). The first key is the major break (region); the second is the minor break (department). Each level gets its own subtotal in its TRAILER.
If you add NODETAIL to the OUTFIL, DFSORT suppresses the detail (data) records. Only the report header (HEADER1), report trailer (TRAILER1), and for each section the section header (HEADER3) and section trailer (TRAILER3) are written. Use NODETAIL when you only want to see the section titles and subtotals, not the individual lines. For example, a report that shows "Department: SALES — Count: 25, Total: 15000" and similar lines for other departments, with no detail lines in between.
TRAILER3 gives you a subtotal per section. The grand total (or overall record count) belongs in TRAILER1, which is written once at the very end of the report. So use TRAILER1=(..., COUNT=..., TOTAL=...) for the overall count and sum across all sections. TRAILER1 can also include literal text such as "GRAND TOTAL" or "END OF REPORT".
| Element | When it appears |
|---|---|
| HEADER1 | Once at the start of the report (e.g. report title). |
| HEADER2 | At the top of each page when LINES= is used (e.g. page header, column titles). |
| HEADER3 | At the start of each section (control-break group). |
| TRAILER3 | At the end of each section (section subtotal/count). |
| TRAILER2 | At the bottom of each page when LINES= is used (e.g. page number). |
| TRAILER1 | Once at the end of the report (grand total, record count). |
Imagine a list of toys grouped by color: all red toys together, then all blue toys. A "control break" is when we switch from red to blue. For each color we want a label at the top ("RED TOYS") and at the bottom a line that says how many toys and maybe the total price. In DFSORT, we first sort the list by color so all reds are together. Then we tell the program: "Whenever the color changes, print a header for the new color and a trailer (subtotal) for the color we just finished." That is control break reporting: labels and subtotals for each group.
1. What must you do before using SECTIONS= for control breaks?
2. What does SKIP=P mean in SECTIONS=?
3. Where do you put the subtotal or count for each section?
4. How do you get a header at the start of each section (e.g. department name)?
5. What does NODETAIL do in a SECTIONS report?