DATASORT Operator
Sort records between header and footer (DATASORT Operator) Example
Scenario -Sort the employee data records (keep the header and footer as it is) based on the country code (from the 60th position of length 2) to the output file.
INPUT - MATEPK.INPUT.PSFILE1
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
ENO NAME TECHNOLOGY COMPANY STATE COUNTRY
========================================================================
001 PAWAN MAINFRAME JPM AP IN
003 SRIDHAR SAS CG OR US
004 VENKATESH ABAP CSC CA US
006 PRASAD HR INFOSYS MI US
002 SRINIVAS TESTING ORACLE TG IN
005 RAVI HADOOP CTS FL US
007 RAJA TESTING IBM CA US
========================================================================
TOTAL NUMBER OF RECORDS: 007
JCL -
----+----1----+----2----+----3----+----4----+----5----+
//MATEPKDC JOB (123),'MATEPK',CLASS=A,MSGCLASS=A,
// MSGLEVEL=(1,1),NOTIFY=&SYSUID
//*
//STEP01 EXEC PGM=ICETOOL
//INDD DD DSN=MATEPK.INPUT.PSFILE1,DISP=SHR
//OUTDD DD DSN=MATEPK.OUTPUT.PSFILE1,
// 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 *
DATASORT FROM(INDD) TO(OUTDD) HEADER(2) TRAILER(2) USING(CTL1)
/*
//CTL1CNTL DD *
SORT FIELDS=(60,2,CH,A)
/*
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//
OUTPUT - MATEPK.OUTPUT.PSFILE1
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
ENO NAME TECHNOLOGY COMPANY STATE COUNTRY
========================================================================
001 PAWAN MAINFRAME JPM AP IN
002 SRINIVAS TESTING ORACLE TG IN
003 SRIDHAR SAS CG OR US
004 VENKATESH ABAP CSC CA US
005 RAVI HADOOP CTS FL US
006 PRASAD HR INFOSYS MI US
007 RAJA TESTING IBM CA US
========================================================================
TOTAL NUMBER OF RECORDS: 007
TOOLMSG (SDSF SPOOL) - Verify TOOLMSG for the return code of the submitted job.
Explaining Example -
- INDD - Specifies the ddname for input file.
- OUTDD - Specifies the ddname for output file.
- TOOLIN DD * - Specifies the ICETOOL statements for DFSORT.
- CTL1CNTL DD * - Specifies the DFSORT statements for processing.
- TOOLMSG - Specifies where to write the ICETOOL processing messages.
- DFSMSG - Specifies where to write the DFSORT processing messages.
- COPY FROM(INDD) TO(OUTDD) - Copies all the records from INDD file to OUTDD file.
- DATASORT FROM(INDD) TO(OUTDD) HEADER(2) TRAILER(2) USING(CTL1) - Filters the records from INDD by 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.