ICETOOL - DATASORT Operator


Sorts data records between header, trailer records in a data set and copies to an output data set.

Copies one or more header records and/or one or more trailer records to the output data set in their original input record order.

while sorting the input dataset data records between the header and trailer records to the output data set.

Thus, the first n records (header records) and/or last n records (trailer records) are kept in place and the data records between them are sorted.


Syntax: -


DFSORT SORT statement must supplied in xxxxCNTL to indicate the control fields for sorting the data records.

The DFSORT control statements are used in xxxxCNTL if USING(xxxx) is specified.


Required Operands: -


FROM -

Specifies the input data set ddname.

DD statements must supply for the ddnames specified.


TO -

Specifies the output data set ddname for the sorted records.

DD statement must supply for the ddname specified.


USING -

Specifies the first 4 characters of the ddname (xxxxCNTL) for the DFSORT control statement data set.

DD statement must supply for xxxxCNTL if USING(xxxx) specified.

TO, USING or TO and USING must be specified.


HEADER, FIRST, TRAILER, LAST –

Defines the number of header records (first u records) and/or trailer records (last v records) to be kept in place.

u and v must be specified as n or +n where n can be 1 to 1000000.


Optional Operands: -


VSAMTYPE -

Specifies the record format for a VSAM input data set (F or V).


Example: -

Below example to sort the employee data records(kept the header and footer as it is) based on the country code(from 60th position of length 2) to output dataset.


Input: -


JCL: -

//MTHUSRR JOB (123),'MTHUSR',CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),   
//             NOTIFY=&SYSUID                                     
//*                                                               
//STEP01   EXEC PGM=ICETOOL                                       
//INDD     DD DSN=MTHUSR.INPUT.DATASET3,DISP=SHR                  
//OUTDD    DD DSN=MTHUSR.OUTPUT.DATASET1,                         
//            DISP=(NEW,CATLG,DELETE),                            
//            SPACE=(TRK,(1,1),RLSE),UNIT=SYSDA,                  
//            DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)        
//TOOLIN   DD *                                                   
  DATASORT FROM(INDD) TO(OUTDD) HEADER(2) TRAILER(2) USING(CTL1)  
/*                                                                
//CTL1CNTL DD *                                                   
  SORT FIELDS=(60,2,CH,A)                                         
/*                                                                
//TOOLMSG  DD DSN=MTHUSR.OUTPUT.TOOLMSG1,DISP=SHR                 
//DFSMSG   DD SYSOUT=*                                            
//                                                                


OUTPUT: -

TOOLMSG: -


MTHUSR.OUTPUT.DATASET1: -


Explaining Solution: -

  • INDD - Specifies the ddname for input dataset.
  • OUTDD - Specifies the ddname for output dataset.
  • TOOLIN DD * - Specifies the ICETOOL statements for DFSORT.
  • CTL1CNTL DD * - Specifies the DFSORT statements for processing.
  • TOOLMSG - Specifies ICETOOL message data set.
  • DFSMSG - Specifies DFSORT message data set.
  • DATASORT FROM(INDD) TO(OUTDD) HEADER(2) TRAILER(2) USING(CTL1) - Sorts the data from INDD based on the USING condition specified in CTL1 ignoring 2 header and 2 trailer records.
  • SORT FIELDS=(60,2,CH,A) – DFSORT condition in CTL1 to sort the records from 60th position of 2 length.