INCLUDE Records Example


Scenario - From the below data, filter the records having the ID is 00001. ID starts from 1st and ends at 5th column in the file.

Input File - MATEPK.SORT.INPUT

----+----1----+----2---+----3---+----4---+---5----+---6----+----7---+----8
00002     Srinivas            Employee
test      test                test
00001     pawan kumar         student

JCL -

----+----1----+----2----+----3----+----4----+----5----+
//MATEPKD  JOB (123),'MTH',NOTIFY=&SYSUID
//*
//STEP01   EXEC PGM=SORT
//SORTIN   DD DSN=MATEPK.SORT.INPUT,DISP=SHR
//SORTOUT   DD DSN=MATEPK.MERGE.OUTPUT,
//            DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
//            SPACE=(CYL,(1,4),RLSE),
//            DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)
//SYSOUT   DD SYSOUT=*
//SYSIN    DD *
     SORT FIELDS=COPY
     INCLUDE COND=(1,05,CH,EQ,C'00001')
/*

Output -

----+----1----+----2----+----3---+----4---+----5---+----6---+----7---+----8
00001     Pawan kumar         Student

Explaining Example -

  1. As a first step, need to get the position of the ID in the file.
  2. The ID starting from 1st position and ends at 5th position as per the input record layout provided. So the length of ID field is 5.
  3. As a second step, need to get the type of the ID.
  4. From the input record layout declaration, ID field is alpha-numeric. So the type is character (CH).
  5. Lastly, the job requirement is to filter the data with the ID as 00001. So the constant is 00001.
  6. INCLUDE COND=(1,05,CH,EQ,C'00001')
    - The above condition specifies that include the records where the ID is 00001 and copied to output file. The output would have the records where the IDs had 00001 at first 5 positions.