SORT FIELDS Example


Scenario - Sort input file in ascending order on first 5 characters and 10 characters from 40th position.

Input File(PS) - MATEPK.SORTDATA.INPUT

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00001    PAWAN     KUMAR     Y         0000010000
00004    SRINIVASA RAO       C         0000020000
00003    SRIDHAR   R         G         0000030000
00002    KAMAL     K         S         0000040000
00006    RAJESH    KUMAR     Y         0000050000
00005    VENKAT    R         Y         0000060000
00004    GURU      R         N         0000010000

JCL -

----+----1----+----2----+----3----+----4----+----5----+
//MATEPKD  JOB (123),'MTH',NOTIFY=&SYSUID
//*
//STEP10  EXEC PGM=SORT
//SYSOUT    DD SYSOUT=*
//SORTIN    DD DSN=MATEPK.SORTDATA.INPUT,DISP=SHR
//SORTOUT   DD DSN=MATEPK.MULTISRT.OUTPUT,
//            DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
//            SPACE=(CYL,(1,4),RLSE),
//            DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)
//SYSIN     DD *
   SORT FIELDS=(1,5,CH,A,40,10,CH,A)
/*

Output -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00001    PAWAN     KUMAR     Y         0000010000
00002    KAMAL     K         S         0000040000
00003    SRIDHAR   R         G         0000030000
00004    GURU      R         N         0000010000
00004    SRINIVASA RAO       C         0000020000
00005    VENKAT    R         Y         0000060000
00006    RAJESH    KUMAR     Y         0000050000

Explaining Example -

  1. SORT FIELDS=(1,5,CH,A,...) - Performs sort on the data in 1 to 5 positions to produce the result in ascending order.
  2. SORT FIELDS=(...,40,10,CH,A) - Performs sort on the result of the above step. Sort performed on the data in 40 to 50 positions to produce the result in ascending order.