Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
As has been shown in other posts, the headers need to be generated as trailers and then sorted to the front of each key group....
Take a look at Header with record statistics
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
SECTIONS=(24,4 - starts a new "section" whenever the value in 24-27 changes (e.g. when it changes from 1000 to 1001). Every record with the same value in 24-27 is part of the same section. So the three 1000 records are in the first section, the two 1001 records are in the second section and the 1002 record is in the third section.
TRAILER3 - adds a trailer record for each section.
'HEADER' - puts the constant 'HEADER' in output positions 1-6 of the trailer record for each section.
24:24,4 - puts input positions 24-27 in output positions 24-27 of the trailer record fo each section. For the first section, that's 1000, for the second section 1001 and for the third section 1002.
31:COUNT=(EDIT=(TT)) - puts the count of records in each section in output positions 31-32 of the trailer record for each section. For the first section, that's 03 (there are three 1000 records), for the second section 02 and for the third section 01.
If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from: