Replace using Sort in JCL

135 Views Asked by At

Good day to all, I am having requirement to replace 3 space with CLR at 15 to 17 position, that is only for data records not for Trailer, I have used below Sort card it is working as expected but the trailer record is duplicated with data after the specified position. so can any one suggest correct logic which I am missed or wrong. Here I am using VB as input.

//STP1  DD EXEC PGM=ICEMAN
//SYSPRINT DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//SORTIN DD DSN=INPUT.FILE
//SORTOUT DD DSN=OUTPUT.FILE
//SYSIN DD *
 INREC IFTHEN=(WHEN=INIT,OVERLAY=(19:C'CLR')),
       IFTHEN=(WHEN=(5,1,CH,EQ,C''),OVERLAY=(19:C'   '))
 OUTREC FIELDS=(1,30)
/*

Input file

712339....@.%. ABCEF 34

602099....@.%^ DCCEF 34

510332....@.#& ZBCEF 34

710001....@.@& BBCEF 34

940105....@.%& YBCEF 34

9999 99999..#

Expected output:

712339....@.%.CLR ABCEF 34

602099....@.%^CLR DCCEF 34

510332....@.#&CLR ZBCEF 34

710001....@.@&CLR BBCEF 34

940105....@.%&CLR YBCEF 34

9999 99999..#

I am getting output as, can see the trailer record having 940105 data after 15-17 POSITION

712339....@.%.CLR ABCEF 34

602099....@.%^CLR DCCEF 34

510332....@.#&CLR ZBCEF 34

710001....@.@&CLR BBCEF 34

940105....@.%&CLR YBCEF 34

9999 99999..# YBCEF 34

1

There are 1 best solutions below

0
Kolusu On

Srinivas,

The control cards you show will NOT duplicate the trailer record and they are not even correct syntax. You should have gotten a syntax error.

Assuming that the trailer record can be identified with 9999 in position 5, here are untested control cards that will give you the desired results.

//STEP0100 EXEC PGM=SORT                      
//SYSOUT   DD SYSOUT=*                        
//SORTIN   DD DISP=SHR,DSN=Your.Input.VB.file
//SORTOUT  DD SYSOUT=*                        
//SYSIN    DD *                               
  OPTION COPY                                 
  INREC IFTHEN=(WHEN=(19,3,CH,EQ,C' ',AND,    
                      05,4,CH,NE,C'9999'),    
      OVERLAY=(19:C'CLR'))                    
/*