Re: Reading and updating the member of a pds using rexx
Posted:
Thu Jan 26, 2017 5:17 pm
by NicC
Rexx on the mainframe is the original. Anything else is a derivative and many have new functions. One version has the ability to run scripts written for almost any derivative. However, you need the manual for the interpreter version that you are using and you need to skim through it at least once and then read, in depth, those parts that you are going to use now.
There are ways of changing data without using CHANGESTR. You could search the string (POS function) for the string that you want to replace, then split (SUBSTR) the string into before, after and not wanted parts and then reassemble with before, new, after.
You could also do it the way Enrico shows, using using ISPF facilities.
Re: Reading and updating the member of a pds using rexx
Posted:
Thu Jan 26, 2017 5:48 pm
by willy jensen
Parse (in my opinion sadly overlooked) can also be used, as in the sample I posted.
cf='old-string'
ct='new-string'
parse value ' 'strip(data.di,'t')' ' with front (cf) back
if length(back)>0 then data.di=substr(front''ct''back,2)
Re: Reading and updating the member of a pds using rexx
Posted:
Thu Jan 26, 2017 6:08 pm
by NicC
or, without losing leading and trailing blanks (which might be important):
data.1 = "out with the old and in with the new stuff"
say data.1
cf='old'
ct='new'
parse value data.1 with front (cf) back
if length(back)>0 then data=front''ct''back
say data.1
Re: Reading and updating the member of a pds using rexx
Posted:
Thu Jan 26, 2017 6:54 pm
by enrico-sorichetti
there are many alternatives that You can Use ...
all depends on the layout of the data to be processed
chiefly on how many occurrences of the from string
for the simpler case something like
buf = " some data with some from string and the rest of the buffer"
f = "from string"
t = "to string"
say buf
l = length(f)
x = pos(f, buf)
if x > 0 then ,
buf = left(buf,x-1) || t || substr(buf,x+l)
say buf
buf = " some data with some from string and the rest of the buffer"
parse var buf head (f) tail
if length(tail) > 0 then ,
buf = head || t || tail
say buf
buf = " there is nothing to be changed"
parse var buf head (f) tail
if length(tail) > 0 then ,
buf = head || t || tail
say buf
might work
Re: Reading and updating the member of a pds using rexx
Posted:
Thu Jan 26, 2017 7:09 pm
by enrico-sorichetti
Rexx on the mainframe is the original. Anything else is a derivative and many have new functions.
unfortunately I have to disagree on the second part
the rexx mainframe might be the original, but has not evolved
probably it is due to the process by which IBM implements product changes
see
http://www.rexxla.org/rexxlang/standards/j18pub.pdf
Re: Reading and updating the member of a pds using rexx
Posted:
Thu Jan 26, 2017 7:44 pm
by arya_starc
Hi NicC,
I coded the below rexx and output is coming ok
/*REXX*/
SAY HI
ADDRESS TSO
FILEI = "VM.LAT.D10A010.PF.JCLLIB.FB.SASH1"
FILEO = "VM.LAT.D10A010.PF.JCLLIB.FB.SASH2"
A = '//STEPLIB DD DSN=VPIDCAMS '
X = OUTTRAP(MEMBERS.)
"LISTDS" FILEI "MEMBERS"
X = OUTTRAP(OFF)
DO I=7 TO MEMBERS.0
X = STRIP(MEMBERS.I)
MEM = FILEI || "(" || X || ")"
SAY MEM
"ALLOC FI(IN) DA('"MEM"') SHR REUSE"
"EXECIO * DISKR IN (STEM MEMB_LINES. FINIS"
"FREE F(IN)"
MEM1 = FILEO || "(" || X || ")"
SAY MEM1
"ALLOC FI(OUT) DA('"MEM1"') SHR REUSE"
STC -DSLISTC DSLISTC
SAY 'ALLOC OUT RC=' RC
DO J = 1 TO MEMB_LINES.0
Y = STRIP(MEMB_LINES.J)
IF POS('PGM=SSIDCAMS',Y) > 0 THEN DO
SAY Y
B = SUBSTR(Y,1,9)
C = ' EXEC PGM=VPIDCAMS,COND(0,NE),'
Y = B C
LINES_OUT.J = Y
SAY Y
SAY HEREREREE
DO L = J+1 TO J+2
D = STRIP(MEMB_LINES.L)
IF POS('PARM=''',D) > 0 THEN DO
SAY TRUE
D = SUBSTR(D,1,10)
E = 'PARM=''&JCLLIB $SETLIB®FS'''
Y = D E
SAY Y
J = J + 1
LINES_OUT.J = Y
END
ELSE IF POS('// ',D) > 0 THEN DO
SAY TRUE
F = '//*'
Y = F
SAY Y
J = J + 1
END
ELSE
NOP
SAY D
END
END
ELSE DO
END
LINES_OUT.J = Y
SAY LINES_OUT.J
END
SAY HERE
"EXECIO "MEMB_LINES.0" DISKW OUT(STEM LINES_OUT. FINIS)"
"FREE F(IN)"
"FREE FI(OUT)"
END
EXIT
I am getting some warning message regarding freed of file
Re: Reading and updating the member of a pds using rexx
Posted:
Thu Jan 26, 2017 9:28 pm
by Akatsukami
That's too bad. If you had shown us a trace with the actual message, we might be able to do more than express sympathy.
Re: Reading and updating the member of a pds using rexx
Posted:
Fri Jan 27, 2017 4:07 am
by NicC
I guess it is because it cannot free 'in' at the end because you already freed it after reading it. Really, you need to spend more time analysing errors.
You appear to have accomplished the task - locking topic.