MainframeMaster

Control Break Reporting

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.

Report Generation
Progress0 of 0 lessons

What Is a Control Break?

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.

Why Sort by the Section Key?

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.

Basic SECTIONS= Syntax

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:

text
1
2
3
4
5
6
7
OUTFIL 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).

Example: Single-Level Control Break by Department

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.

text
1
2
3
4
5
6
7
8
9
10
11
12
SORT 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.

SKIP=P vs SKIP=nL

These options control how sections are separated in the report:

SKIP options in SECTIONS=
OptionEffect
SKIP=PStart each section on a new page. Use when each group (e.g. each department) should appear on its own page.
SKIP=nLKeep 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.

Section Header (HEADER3): What to Put In

HEADER3 is printed once at the start of each section. Common uses:

  • Section title and key value — e.g. "Department: " followed by the field that defines the section (30,5 in the example). That way each group is clearly labeled.
  • Column headers — If you do not use a global page header for column titles, you can repeat column headers in HEADER3 so each section has its own header line (e.g. "Std num", "Std name", "Department", "Total marks").
  • Blank lines — Use X or n to add blank lines before or after the title for readability.

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.

Section Trailer (TRAILER3): Counts and Subtotals

TRAILER3 is printed once at the end of each section—after the last detail record of the group. Typical content:

  • COUNT= — Number of records in that section. Useful for "Records in this department: 25".
  • TOTAL= or TOT= — Sum of a numeric field over the section. Use for subtotals (e.g. total sales for the department).
  • MIN=, MAX=, AVG= — Minimum, maximum, or average of a field in the section. Common in reports that show stats per group.
  • Section key value — You can repeat the section key (e.g. 30,5) in TRAILER3 so the subtotal line is labeled (e.g. "Subtotal for SALES: 15000").

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.

Multi-Level Control Breaks

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.

NODETAIL: Summary-Only Report

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.

Report Trailer (TRAILER1) for Grand Total

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

Control break elements
ElementWhen it appears
HEADER1Once at the start of the report (e.g. report title).
HEADER2At the top of each page when LINES= is used (e.g. page header, column titles).
HEADER3At the start of each section (control-break group).
TRAILER3At the end of each section (section subtotal/count).
TRAILER2At the bottom of each page when LINES= is used (e.g. page number).
TRAILER1Once at the end of the report (grand total, record count).

Explain It Like I'm Five

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.

Exercises

  1. Your file has region at 1,6 and department at 10,5. You want a section for each region with a header "Region: " and the region value, and a trailer with COUNT= for the region. What SORT FIELDS= and SECTIONS= would you use (conceptually)?
  2. When would you use SKIP=P instead of SKIP=2L?
  3. What is the purpose of NODETAIL in a SECTIONS report?

Quiz

Test Your Knowledge

1. What must you do before using SECTIONS= for control breaks?

  • Use OPTION COPY only
  • Sort (or merge) the data by the same field(s) you use in SECTIONS= so records in each group are together
  • Use INCLUDE only
  • Omit TRAILER3

2. What does SKIP=P mean in SECTIONS=?

  • Skip the first page
  • Start each section on a new page—each control-break group begins on its own page
  • Print only
  • Skip trailer

3. Where do you put the subtotal or count for each section?

  • In HEADER2
  • In TRAILER3—the section trailer that prints after each control-break group
  • In BUILD= only
  • In TRAILER1 only

4. How do you get a header at the start of each section (e.g. department name)?

  • Use HEADER2 only
  • Use HEADER3= in SECTIONS=—the section header prints at the start of each control-break group
  • Use TRAILER3
  • Use NODETAIL

5. What does NODETAIL do in a SECTIONS report?

  • Removes headers
  • Suppresses detail records—only section headers and trailers (and report header/trailer) are written; no data lines in between
  • Removes trailers
  • Prints one record per section only