I am trying to create a new job, based on the sample job keyed-in by user in a REXX panel. Please note that user also provides few other details to be updated in the new job.
I had used POS,OVERLAY functions to override/replace the string/values that user provided in the rexx panel.
when the search string length is more than the string to be replaced, the result is not as expected.
To give you an example about the problem:
Sample job code:
//JS0010 EXEC PROC1,
// HLQ1='SYS1',
// HLQ2='SYSPN',
// DMPUBLIB='SYS1.COD.ORANGE.PROCESS',
// CNTL='AAAA.BBBB.CCC.PR.CNTL',
// MEM1='CNTL1',
// MEM2='CNTL2'
//*
If “REXX is strictly required by management” then another simple solution would be:
Code:
Do i = 1 to OldWords.0
If 0 < Pos( OldWords.i, TextLine ) Then Do
Parse Var TextLine PreText (OldWords.i) PostText
TextLine = PreText || NewWords.i || PostText
End
End i
When working with real “words” (no spaces in between) in REXX there is even better solution, to avoid bad looking “stems”.
Code:
OldWords = ‘CF010X CF010XC’
NewWords = ‘CN1 CN2’
Do i = 1 To Words(OldWords)
CheckWord = SubWord( OldWords, i )
If 0 < Pos( CheckWord, TextLine ) Then Do
Parse Var TextLine PreText (CheckWord) PostText
TextLine = PreText || SubWord( NewWords, i ) || PostText
End
End i
When working with real “words” (no spaces in between) in REXX there is even better solution, to avoid bad looking “stems”.
Code:
OldWords = ‘CF010X CF010XC’
NewWords = ‘CN1 CN2’
Do i = 1 To Words(OldWords)
CheckWord = SubWord( OldWords, i )
If 0 < Pos( CheckWord, TextLine ) Then Do
Parse Var TextLine PreText (CheckWord) PostText
TextLine = PreText || SubWord( NewWords, i ) || PostText
End
End i
P.S.
In my example, both functions SubWord do require the third optional parameter; the default value is not 1:
Code:
CheckWord = SubWord( OldWords, i, 1 )
. . . . . etc. . . . . . .
Your code does not work because You did not care to try to understand how overlay works
try this
Code:
in = "// MEM1='OLD',"
chgs = "l2 l03 l004 l0005"
parse var in head "='" body "'" tail
say "head" head
say "body" body
say "tail" tail
say "old >>>"in"<<<"
say
do i = 1 to words(chgs)
say "new >>>" || head || "='" || word(chgs,i) || "'" || tail || "<<<"
end
to get ...
Code:
old >>>// MEM1='OLD',<<<
new >>>// MEM1='l2',<<<
new >>>// MEM1='l03',<<<
new >>>// MEM1='l004',<<<
new >>>// MEM1='l0005',<<<
Thank you for your solution & suggestion.
Regarding the solution,
My search string do not start/preceded always with a specific char (like '=', ',' etc).
After referring multiple suggestions from the forum, I am able to achieve the desired results with parse function.
Below is the customized solution.
PRETEXT=' ' ; POSTTEXT=' ';
if pos(srchstr,srcline) > 0 then
do
PARSE VAR srcline PRETEXT (srchstr) POSTTEXT
srcline = PRETEXT||replstr||POSTTEXT
end
When working with real “words” (no spaces in between) in REXX there is even better solution, to avoid bad looking “stems”.
Code:
OldWords = ‘CF010X CF010XC’
NewWords = ‘CN1 CN2’
Do i = 1 To Words(OldWords)
CheckWord = SubWord( OldWords, i )
If 0 < Pos( CheckWord, TextLine ) Then Do
Parse Var TextLine PreText (CheckWord) PostText
TextLine = PreText || SubWord( NewWords, i ) || PostText
End
End i
P.S.
In my example, both functions SubWord do require the third optional parameter; the default value is not 1:
Code:
CheckWord = SubWord( OldWords, i, 1 )
. . . . . etc. . . . . . .
I have tried parse like this earlier, which did not give the desired results. (Syntax differs.)
PRETEXT=' ' ; POSTTEXT=' ';
if pos(srchstr,srcline) > 0 then
do
PARSE VAR srcline PRETEXT srchstr POSTTEXT
srcline = PRETEXT||replstr||POSTTEXT
end
which gave below output:
before: //PN2G010X JOB CZXXX002,'YYYYYY',CLASS=J,REGION=0M,TIME=1440,
After: //PN2G010XGN2G010XCZXXX002,'YYYYYY',CLASS=J,REGION=0M,TIME=1440,
Have you considered using ISPF File Tailoring? It is specifically designed to merge user input from a panel with JCL in a skeleton.
Hi,
Yes, I am aware of File tailoring services. To use tailored services a fixed template/skeleton is required, which we wanted to avoid for our requirement.
I highly recommend to eliminate all unneeded operations from any of your code. For instance, all useless initialization of variables, like those ones:
posvar = 0
PRETEXT = ‘’
POSTTEXT = ‘’
All of those variables are assigned correct required values by just the next statements; in this manner you may get 30%-50% of your code filled with this unneeded garbage. This is as senseless as