OUTREC Reformatting records with IFTHEN Example


Scenario - Reformatting records to hide the student marks belongs to the dept1 using IFTHEN.

Input File - MATEPK.SORT.INPUT01 - FB file of 80 length

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00001     student1           dept1          560
00003     student3           dept2          520
00004     student4           dept1          540
00005     student5           dept2          500
00002     student2           dept3          510

JCL -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
//MATEPKD  JOB (123),'MTH',NOTIFY=&SYSUID
//*
//STEP01   EXEC PGM=SORT
//SORTIN   DD DSN=MATEPK.SORT.INPUT01,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 *
     OPTION COPY
     OUTREC IFTHEN=(WHEN=INIT,BUILD=(1:1,80)),
          IFTHEN=(WHEN=(30,5,CH,EQ,C'dept1'),OVERLAY=(45:C'***')),
          IFTHEN=(WHEN=NONE,BUILD=(1:1,80))
/*

Output -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00001     student1           dept1          ***
00003     student3           dept2          520
00004     student4           dept1          ***
00005     student5           dept2          500
00002     student2           dept3          510

Explaining Example -

  1. OUTREC IFTHEN=(WHEN=INIT,BUILD=(1:1,80)),..) - Copies the 80 bytes data from input file to output as it is.
  2. IFTHEN=(WHEN=(30,5,CH,EQ,C'dept1'),OVERLAY=(45:C'***')) - overlays the marks of the student with ‘***’ who are belong to dept1.
  3. IFTHEN=(WHEN=NONE,BUILD=(1:1,80)) - If no matches to conditions specified in WHEN, copy the 80 bytes data from input file to output as it is.