CAWABATC tool can be used for replacing a particular string in all the members of a PDS provided CAFM is available in your shop. However this does not work fine when the target string is longer than source string and the tool overwrites spaces next to the string to be replaced with the new string.
Below REXX tool works perfectly fine for replacing a particular string in all the members of a PDS. Save the REXX code with member name 'STRREPL' in a PDS and you can use below mentioned JCL to run the REXX code in batch. Use your own PDS name in SYSEXEC file.
REXX code :
/* REXX */
PARSE UPPER PULL DSN
PARSE UPPER PULL SRCSTR
PARSE UPPER PULL TRGSTR
SRCSTR = SPACE(SRCSTR)
TRGSTR = SPACE(TRGSTR)
DUMMY = OUTTRAP("MEMB.","*")
ADDRESS TSO
"LISTDS '"DSN"' MEMBERS"
DUMMY = OUTTRAP("OFF")
DO I = 7 TO MEMB.0
DSN1 = "'"||DSN||"("||SPACE(MEMB.I,0)||")'"
DROP OUT.
ADDRESS TSO
"ALLOC F(IN) DS("DSN1") SHR"
"EXECIO * DISKR IN (FINIS STEM IN."
"FREE F(IN)"
T = 0
DO S = 1 TO IN.0
STRING = IN.S
CALL STRRPL
T = T + 1
OUT.T = STRING
END
OUT.0 = IN.0
ADDRESS TSO
"ALLOC F(OUT) DS("DSN1") SHR"
"EXECIO * DISKW OUT (FINIS STEM OUT."
"FREE F(OUT)"
END
EXIT
STRRPL:
DO FOREVER
POSN = POS(SRCSTR,STRING)
IF POSN > 0
THEN DO
SUBLEN= LENGTH(SRCSTR)
STRLEN= LENGTH(STRING)
FPART = SUBSTR(STRING,1,POSN-1)
SPART = SUBSTR(STRING,POSN+SUBLEN)
STRING= FPART||TRGSTR||SPART ; END
ELSE DO
LEAVE ;END
END
RETURN
PARSE UPPER PULL DSN
PARSE UPPER PULL SRCSTR
PARSE UPPER PULL TRGSTR
SRCSTR = SPACE(SRCSTR)
TRGSTR = SPACE(TRGSTR)
DUMMY = OUTTRAP("MEMB.","*")
ADDRESS TSO
"LISTDS '"DSN"' MEMBERS"
DUMMY = OUTTRAP("OFF")
DO I = 7 TO MEMB.0
DSN1 = "'"||DSN||"("||SPACE(MEMB.I,0)||")'"
DROP OUT.
ADDRESS TSO
"ALLOC F(IN) DS("DSN1") SHR"
"EXECIO * DISKR IN (FINIS STEM IN."
"FREE F(IN)"
T = 0
DO S = 1 TO IN.0
STRING = IN.S
CALL STRRPL
T = T + 1
OUT.T = STRING
END
OUT.0 = IN.0
ADDRESS TSO
"ALLOC F(OUT) DS("DSN1") SHR"
"EXECIO * DISKW OUT (FINIS STEM OUT."
"FREE F(OUT)"
END
EXIT
STRRPL:
DO FOREVER
POSN = POS(SRCSTR,STRING)
IF POSN > 0
THEN DO
SUBLEN= LENGTH(SRCSTR)
STRLEN= LENGTH(STRING)
FPART = SUBSTR(STRING,1,POSN-1)
SPART = SUBSTR(STRING,POSN+SUBLEN)
STRING= FPART||TRGSTR||SPART ; END
ELSE DO
LEAVE ;END
END
RETURN
JCL step to excute the tool in batch :
//STEP1 EXEC PGM=IKJEFT01,PARM='STRREPL'
//*
//SYSTSIN DD *
N123DF.G6279.COMMON.TEST
S6578
S68779
/*
//SYSTSPRT DD SYSOUT=*
//*
//SYSEXEC DD DSN=N123DF.REXX.CODE,DISP=SHR
//* N123DF.REXX.CODE CONTAINS MEMBER STRREPL
//*
//SYSTSIN DD *
N123DF.G6279.COMMON.TEST
S6578
S68779
/*
//SYSTSPRT DD SYSOUT=*
//*
//SYSEXEC DD DSN=N123DF.REXX.CODE,DISP=SHR
//* N123DF.REXX.CODE CONTAINS MEMBER STRREPL
Can you explain me the working of above rexx
ReplyDeletedo you know whether is possible to rewrite just the members that had been replaced with new date/time and leaving the remaining no changed with the original date/time? The reason is why all the members in the PDS is cleaned-up the updates...thanks.
ReplyDeletedo you know whether is possible to rewrite just the members that had been replaced with new date/time and leaving the remaining no changed with the original date/time? The reason is why all the members in the PDS is cleaned-up the updates...
ReplyDeleteIf is possible, could you please send me the solution to my e-mail apacolo@gmail.com?
thanks.