z/OS DFSORT Application Programming Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Example 2

z/OS DFSORT Application Programming Guide
SC23-6878-00

DATASORT FROM(IN) TO(OUT) HEADER(2) TRAILER(3) USING(CTL2)   

This example illustrates how you can sort the data records between header records (first records) and trailer records (last records), and modify just the data records or the header, data and trailer records.

The CTL2CNTL data set contains:
  INREC IFTHEN=(WHEN=(24,2,CH,EQ,C'23'),      
    OVERLAY=(30:C'Old'))                      
  SORT FIELDS=(1,14,CH,A)                     
  OUTFIL FNAMES=OUT,                          
    IFTHEN=(WHEN=(24,2,CH,EQ,C'23'),          
      OVERLAY=(35:C'First'))
The input records look like this:
Header 1       2008/04/23
Header 2       2008/04/23
Geometry       2008/04/24
Algebra        2008/04/23
Trigonometry   2008/04/24
Calculus       2008/04/25
Geography      2008/04/25
History        2008/04/23
Trailer 1      2008/04/23
Trailer 2      2008/04/23
Trailer 3      2008/04/23

We want to keep the two Header records and the three Trailer records in place and sort the other records by the CH field in positions 1-14. We want to put 'Old' in positions 30-32 of each data record (but not the Header or Trailer records) that has '23' in positions 24-25. We want to put 'First' in positions 35-39 of each record (Header, data and Trailer) that has '23' in positions 24-25.

We use HEADER(2) and TRAILER(3) to indicate the first two records and last three records should not be sorted. We use the INREC statement to add 'Old' to data records that have '23' in positions 24-25. INREC applies to the data records, but not to the Header and Trailer records. We use the SORT statement to sort ascending on positions 1-14. We use the OUTFIL statement to add 'First' to Header, data and Trailer records that have '23' in positions 24-25. OUTFIL applies to all of the records.

The output records would look like this:
Header 1       2008/04/23         First       
Header 2       2008/04/23         First       
Algebra        2008/04/23    Old  First       
Calculus       2008/04/25                     
Geography      2008/04/25                     
Geometry       2008/04/24                     
History        2008/04/23    Old  First       
Trigonometry   2008/04/24                     
Trailer 1      2008/04/23         First       
Trailer 2      2008/04/23         First       
Trailer 3      2008/04/23         First       

Note that we could use FIRST(2) and LAST(3) instead of HEADER(2) and TRAILER(3).

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014