Sorting records between headers and trailers

You can use ICETOOL's DATASORT operator to sort the data records in a data set without sorting the header or trailer records. You use the following operands to tell DATASORT the number of header records, trailer records, or header and trailer records in your data set:

DATASORT does not require an "identifier" in the header or trailer records; it can treat the first x records as header records and the last y records as trailer records.

You must specify a USING data set to specify a DFSORT SORT statement that tells DATASORT the fields you want to use to sort your data records. You can use various other DFSORT statements as well; see z/OS DFSORT Application Programming Guide for details.

DATASORT sorts the data records between your header records (first x records of the data set) and trailer records (last y records of the data set) while keeping the header and trailer records in place.

Suppose you have input records that look like this:
2008/04/23          
Geometry            
Algebra             
Trigonometry        
Calculus            
0004                
End of data set     
The first record is a header record containing a date, the last two records are trailer records containing a count and an end indicator, respectively, and the records between the header and trailer records are data records containing Subject names. You want to create an output data set with the Subject names sorted but the header and trailer records in their original places. Write the following ICETOOL statement:
DATASORT FROM(IN) TO(OUT) HEADER TRAILER(2) USING(CTL1)
Include the following DFSORT SORT statement in CTL1CNTL:
   SORT FIELDS=(1,16,CH,A)
The output records would look like this:
2008/04/23        
Algebra           
Calculus          
Geometry          
Trigonometry      
0004              
End of data set

For complete details of DATASORT, as well as more examples, see z/OS DFSORT Application Programming Guide.