Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 8: JCL Sort & Merge


OUTREC IF THEN clauses

Reformat different records in different ways by specifying how build, overlay, find/replace, or group operation items are applied to records that meet given criteria. IFTHEN clauses let you use sophisticated conditional logic to choose how different record types are reformatted.

Example :-

Input file:-

----+----1----+----2----+----3 JOHN MON 08000 AKSHAY TUE 10000 SMITH WED 25000 JOHN SUN 28000 STEVE MON 20000 VIJAY XXX 24000 VIJAY SUN 30000

Requirement: If input file have day-of-week as SUN or MON, then write ‘YES’ at 33 position of output file else write ‘NO’

JCL Code Solution:

//SORTSTEP EXEC PGM=SORT //SORTIN DD DSN=DEPT.EMPL.DATA.OUTPUT1,DISP=SHR //SORTOUT DD DSN=DEPT.EMPL.DATA.OUTPUT2, // DISP=(,CATLG,DELETE), // DCB=(RECFM=FB,LRECL=35,BLKSIZE=0), // UNIT=TEST,SPACE=(CYL,(50,10),RLSE) //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSIN DD * SORT FIELDS=COPY OUTREC IFTHEN=(WHEN(11,3,CH,EQ,C'SUN'), - OVERLAY=(33:C'YES')), - IFTHEN=(WHEN(11,3,CH,EQ,C'MON'), - OVERLAY=(33:C'YES')), - IFTHEN=(WHEN=NONE,OVERLAY=(33:C'NO')) /*

Output file:

----+----1----+----2----+----3----+ JOHN MON 08000 YES AKSHAY TUE 10000 NO SMITH WED 25000 NO JOHN SUN 28000 YES STEVE MON 20000 YES VIJAY XXX 24000 NO VIJAY SUN 30000 YES

Explanation:

  • Statement ‘SORT FIELDS=COPY’ is used here to indicate that all records will be copied from input file to output file.
  • Next statement OUTREC IFTHEN is coded to specify that if field at position (11-13 i.e. length-3) contains string ‘SUN’ or ‘MON’ then it should write string ‘YES’ at 33 position of output file. If it is not matching then string ‘NO will be written.






© copyright mainframebug.com
Privacy Policy