Sorts the records (SORT Operator) 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----+
//MATEPKIT JOB (123),'MATEPK',CLASS=A,MSGCLASS=A,
//             MSGLEVEL=(1,1),NOTIFY=&SYSUID
//*
//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)
/*
//TOOLMSG  DD SYSOUT=*
//DFSMSG   DD SYSOUT=*
//

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

TOOLMSG (SDSF SPOOL) - Verify TOOLMSG for the return code of the submitted job.

SORT TOOLMSG

Explaining Example -

  • INDD - Specifies the ddname for input file.
  • OUTDD - Specifies the ddname for output file.
  • TOOLIN DD * - Specifies the ICETOOL statements for DFSORT.
  • TOOLMSG - Specifies where to write the ICETOOL processing messages.
  • DFSMSG - Specifies where to write the DFSORT processing messages.
  • CTL1CNTL DD * - Specifies the DFSORT statements for processing.
  • SORT FROM(INDD) TO(OUTDD) USING(CTL1) - Sorts the indd records and copies to OUTDD based on the selection criteria in CTL1.
  • SORT FIELDS=(50,2,CH,A) - Sorts the records in ascending order based on the data of length 15 from 6th position.