Header and Trailer – SORT Detail records between these
Understanding Header and Trailer Processing: In mainframe data processing, it’s essential to handle files that contain Header and Trailer records correctly. Standard sort utilities sort all records — including headers and trailers — unless explicitly handled. To avoid rearranging records post-sort, ICETOOL offers options that allow detail records to be sorted while preserving headers and trailers in their original positions.
What is Header-Detail-Trailer Structure?
A Header-Detail-Trailer file format is a structured layout where:
Header Record: Contains metadata such as creation date or file ID.
Detail Records: Core business records that need to be sorted or processed.
Trailer Record: Summary information like total record count or checksum.
File Structure with Header and Trailer
HEADER20250727001 <- Header record
1111AAAA <- Detail record
3333CCCC <- Detail record
2222BBBB <- Detail record
TRAILER0003 <- Trailer record (3 detail records)
DFSORT Techniques for Header and Trailer Processing
Method 1: Using DATASORT Operator (Recommended)
DATASORT in ICETOOL is built to sort detail records while preserving headers and trailers:
Scenario -1: Let’s say we want to SORT an input file by a section that is divided by a constant keyword or symbol or some unique identifier. We can use the WHEN=GROUP function, we can add group numbers after the end of the records. Then we can SORT by the group number and by the key. Finally, we can remove the group numbers.
Scenario -2: This example illustrates how you can SORT and INCLUDE groups of FB records depending on a value in the first record of each group…
Input File
1RPT.SRIHARI
LINE 1 FOR REPORT 1
LINE 2 FOR REPORT 1
...
1RPT.VICKY
LINE 1 FOR REPORT 2
LINE 2 FOR REPORT 2
...
1RPT.FRANK
LINE 1 FOR REPORT 3
LINE 2 FOR REPORT 3
...
1RPT.DAVID
LINE 1 FOR REPORT 4
LINE 2 FOR REPORT 4
...
Each report starts with ‘RPT.reptname’ in positions 2-13…
1RPT.SRIHARI
LINE 1 FOR REPORT 1 SRIHARI
LINE 2 FOR REPORT 1 SRIHARI
...
1RPT.VICKY VICKY
LINE 1 FOR REPORT 2 VICKY
LINE 2 FOR REPORT 2 VICKY
...
We use a SORT statement to sort ascending on the reptname…
1RPT.DAVID DAVID
LINE 1 FOR REPORT 4 DAVID
LINE 2 FOR REPORT 4 DAVID
...
1RPT.FRANK FRANK
LINE 1 FOR REPORT 3 FRANK
LINE 2 FOR REPORT 3 FRANK
...
1RPT.SRIHARI SRIHARI
LINE 1 FOR REPORT 1 SRIHARI
LINE 2 FOR REPORT 1 SRIHARI
...
We use an OUTFIL statement to only INCLUDE the records with a reptname of FRANK or SRIHARI…
1RPT.FRANK
LINE 1 FOR REPORT 3
LINE 2 FOR REPORT 3
...
1RPT.SRIHARI
LINE 1 FOR REPORT 1
LINE 2 FOR REPORT 1