Sorts the records (SORT Operator)


SORT operator sorts the records in the input file and copies the records into the output files. It allows up to 10 input files.

Syntax -

SORT Operator

Required Operands


  • FROM - specifies ddname of the input file. It is mandatory when FROM operand is coded.
  • JKFROM - used to JOIN KEYS for matching records. It is mandatory when USING(xxxx) is coded. In xxxxCNTL, a JOINKEYS statement should provide F1=ddname1 for the F1 file, F2=ddname2 for the F2 file, JOIN and REFORMAT statements according to the requirement.
  • USING - specifies the first 4-characters of the ddname (xxxxCNTL) for the DFSORT control statement. XXXX name is the user-defined name. Either TO, USING, or both operands can code at the same time.

Optional Operands


  • TO - specifies 1 to 10 ddnames of output files. TO and USING operands can code at the same time.
  • VSAMTYPE - specifies the record format for a VSAM input file. It should be either F (fixed-length) or V (variable-length) record processing.

Example -


Scenario - Sort the employee records based on employee name (15 character length from 6th position).

INPUT - MATEPK.INPUT.PSFILE

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
001  PAWAN         MAINFRAME           JPM       AP        IN
002  SRINIVAS      TESTING             ORACLE    TG        IN
003  SRIDHAR       SAS                 CG        OR        US
004  VENKATESH     ABAP                CSC       CA        IN
005  RAVI          HADOOP              CTS       FL        US
006  PRASAD        HR                  INFOSYS   MI        US
007  RAJA          TESTING             IBM       CA        US

JCL -

----+----1----+----2----+----3----+----4----+----5----+
...
//STEP01   EXEC PGM=ICETOOL
//INDD     DD DSN=MATEPK.INPUT.PSFILE,DISP=SHR
//OUTDD    DD DSN=MATEPK.OUTPUT.PSFILEST,
//            DISP=(NEW,CATLG,DELETE),VOLUME=SER=DEVHD4,
//            SPACE=(TRK,(1,1),RLSE),UNIT=SYSDA,
//            DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
//TOOLIN   DD * 
  SORT   FROM(INDD) TO(OUTDD) USING(CTL1)
/*
//CTL1CNTL DD *
  SORT FIELDS=(6,15,CH,A)
/*
...

OUTPUT - MATEPK.OUTPUT.PSFILE

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
001  PAWAN         MAINFRAME           JPM       AP        IN
006  PRASAD        HR                  INFOSYS   MI        US
007  RAJA          TESTING             IBM       CA        US
005  RAVI          HADOOP              CTS       FL        US
003  SRIDHAR       SAS                 CG        OR        US 
002  SRINIVAS      TESTING             ORACLE    TG        IN
004  VENKATESH     ABAP                CSC       CA        IN