Joined: 30 Nov 2010 Posts: 5 Location: Pune, India
Hello Everyone!!
I have written REXX code to replace particular string from all members of a PDS.However while retrieving contents of PDS member, REXX is concatenating lines in 72 chars instead of reading line by line which is causing string break for instance, I want to replace $CYC by '5072' however in some places '$CYC' is read as '$C' in one line and 'YC' in another line due to which '$CYC" couldn't be replaced. Here's my REXX
Code:
DSN= 'USERID.PDS'
SRCSTR = SPACE('$CYC')
TRGSTR = SPACE('5072')
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
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
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
Could you please let me know how to make REXX read 1 line at time without concatenating it.
Joined: 10 Dec 2010 Posts: 11 Location: Orlando, FL
I think I unerstand the issue, and if so, the edit macro will not solve it. what I am hearing from you is that the character string for which you are searching can break across a line boundary and is, therefore not discoverable by a simple POS, nor by an ISREDIT FIND. In order to understand the issue better, I would like to see the DCB attributes of the PDS and an example of a few lines of a member as it appears in EDIT.
As a work-around, assuming that the records are of equal length, you could try S1 = S+1; STRING = IN.S||IN.S1. Then POSN will find an occurrence which is broken across the record boundary. Then you will follow your replacement logic. But it's not clear how you would then split the STRING back into IN.S and IN.S1 unless the total length of the two concatenated records remains constant after the substitution.
Joined: 30 Nov 2010 Posts: 5 Location: Pune, India
Hi John,
Thanks for the response..The string to be replaced is in different places within the PDS member so I don't have a specific position.Here's DCB attributes of my PDS:
RECFM=FB,LRECL=80,BLKSIZE=27920
Joined: 10 Dec 2010 Posts: 11 Location: Orlando, FL
What you are doing in your program looks perfectly reasonable, but the behavior we are both observing in your program is bizarre! I've never seen EXECIO fail to honor record boundaries the way it appears to be happening in this program. Try a minimal program on one member of the PDS. Allocate it, EXECIO * DISKR, the DO S = 1 to IN.0; SAY IN.S; END. Do you still see this concatenation of records?
Joined: 30 Nov 2010 Posts: 5 Location: Pune, India
Hi John,
Thanks for the response..The string to be replaced is in different places within the PDS member so I don't have a specific position.Here's DCB attributes of my PDS:
RECFM=FB,LRECL=80,BLKSIZE=27920
3) Once PDS is created, I'm copying members from a MASTER PDS. Also renaming members as per the input provided in step 1 using following command:
Copying:
"LMCOPY FROMID("INDD1") TODATAID("OUTDD1") FROMMEM(*)
REPLACE PACK"
4) After all the members are copied and renamed, I'm replacing certain 'control' string like 'test node', 'cycle' etc with the values/input provided in step 1.
Joined: 10 Dec 2010 Posts: 11 Location: Orlando, FL
Well, it's obvious what to do. It looks as if the record boundaries are delimited by the "://h" string. So before fou can discover the strings you want to replica, you have to reconstruct the file format to the original records. Your REXX programming skills appear to be solid, as is your strategy. So you can use the approach of building a temp = IN.S||IN.S1, as I suggested before. Then you will scan temp for the delimiter string and build a new array (NEW.?) with the logical records as you see them when you view the original PDS member. Then your scan and replace logic will work as you loop through the NEW. array. The stumper is still the question of how the records of the original PDS member became reformatted in this very normal, very reasonable procedure. Is there any chance that the input PDS is RECFM=VB? Even so, I don't think REXX EXECIO gives you the RDW, does it? I'm just musing out loud to try to account for the "://h" string...