(Originally posted 2008-07-31.)
As I mentioned in this blog post DFSORT just shipped a new FINDREP function to do “find and replace”.
I mentioned an example of where I might use it to replace SMFIDs in SMF records. That example generally works well.
But suppose (say, for SMF 42-6 Data Set Performance records) I want to replace “SYS1” with “MVSA” but don’t want to replace “SYS1.” with “MVSA.”.
There’s something useful about FINDREP that saves the day: Only the first match is used. So consider the following FINDREP example:
OPTION COPY INREC FINDREP=(INOUT=(C'SYS1.',C'SYS1.',C'SYS1',C'MVSA'))
With this code any data set references of the form “SYS1.” are transformed to themselves – and the cursor moves past them – whereas any other “SYS1” reference is transformed to “MVSA”.
It makes sense to put the most restrictive find string first. Otherwise the following wouldn’t work…
OPTION COPY INREC FINDREP=(INOUT=(C'SYS1.MODIFYME',C'MVSA.MODIFYME', C'SYS1.',C'SYS1.', C'SYS1',C'MVSA'))
which will change “SYS1.MODIFYME” into “MVSA.MODIFYME” but no other “SYS1.” string (unless it starts with “SYS1.MODIFYME”).
Of course, given you can use FINDREP as part of IFTHEN there’s a lot more you can do with it. But for now I just wanted to point out the “first hit wins” characteristic that can be useful.