Skip to content

REXX script for replacing substring in some members of dataset

AnatolyKolbasin edited this page Feb 8, 2021 · 1 revision

REXX script for replacing substring in some members of dataset

MASSREPL was created to replace substring with new one in some members of dataset on z/OS

Link to REXX script sources (MASSREPL)

Script configuration before execution

  1. Replace dataset's members names MEMBER1,MEMBER2,.. with members you need:
  • membersToProcess='MEMBER1 MEMBER2 MEMBER3 MEMBER4'
  1. Put the script to your REXX-library

Execution:

Run JCL job with step:

//RUNSCRPT  EXEC PGM=IKJEFT01,DYNAMNBR=30,REGION=0M,         
//          PARM='MASSREPL USR01.USRHLQ.USRLIB HLQ1 HLQ2'
//SYSEXEC   DD   DSN=USR01.USRHLQ.REXX,DISP=SHR                  
//SYSTSPRT  DD   SYSOUT=*                                    
//SYSTSIN   DD   DUMMY                                       
  • USR01.USRHLQ.USRLIB - dataset with members to be changed

  • HLQ1 HLQ2 - substring HLQ1 to be replaced with substring HLQ2

Script source:

/* REXX */
trace off
parse arg parms
parms = translate(parms,' ',',')

/*parms = 'USR01.USRHLQ.USRLIB &HLQ1 &HLQ2'*/
parse var parms dataset oldString newString

/* Globals */
membersToProcess='MEMBER1 MEMBER2 MEMBER3 MEMBER4'
/* End of globals */

/**************/
/* Main loop  */
/**************/
say 'Start replacing substring 'oldString' by 'newString
say 'in members of library 'dataset
say
do i=1 to words(membersToProcess)
   member = word(membersToProcess,i)
   fullname = dataset'('member')'
   say 'Process member 'member
    call processFile fullname oldString newString
end
say 'Processing completed'

Return
/**************************/
/* Update member contents */
/**************************/
processFile:
  parse arg fileName oldSubstr newSubstr

  address TSO
  drop lines.
  "ALLOC F(UPDATEDD) DA('"fileName"') OLD"
  "EXECIO * DISKR UPDATEDD (STEM lines. FINIS"
  occ = 0
  do ix = 1 to lines.0
   parse var lines.ix strPrefix (oldSubstr) strSuffix
   if strSuffix <> ''
    then do
          lines.ix = strPrefix || newSubstr || strSuffix
          occ = occ + 1
         end
   else lines.ix = strPrefix
  end

  "EXECIO * DISKW UPDATEDD (STEM lines. FINIS"
  "FREE F(UPDATEDD)"
  say occ 'occurrences processed'

return

z/OS System operating

SMP/E

Mainframe automation solutions and best practices

z/OS DevOps scripts

RACF

REXX scripts

ISPF

HSM

Useful tricks

Batch jobs (JCLs)

z/OS System operating

z/OS Subsystem operating

Clone this wiki locally