|
View previous topic :: View next topic
|
| Author |
Message |
hsrPulivarthi19
New User
Joined: 04 Mar 2021 Posts: 6 Location: India
|
|
|
|
Hi,
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'
//*
Expected,in New job:
//JS0010 EXEC PROC1,
// HLQ1='SYS1',
// HLQ2='SYSPN',
// DMPUBLIB='SYS1.COD.ORANGE.PROCESS',
// CNTL='AAAA.BBBB.CCC.PR.CNTL',
// MEM1='NEW1',
// MEM2='NEW2'
//*
Output with my code:
//JS0010 EXEC PROC1,
// HLQ1='SYS1',
// HLQ2='SYSPN',
// DMPUBLIB='SYS1.COD.ORANGE.PROCESS',
// CNTL='AAAA.BBBB.CCC.PR.CNTL',
// MEM1='NEW11',
// MEM2='NEW22'
//*
I read sample job to a stem var. The search string and the replace strings both are in rexx program variables.
Any suggestions would be of great help. Thank you. |
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1442 Location: Bamberg, Germany
|
|
|
|
| Use code tags when presenting Code/Data to make it more readable for others. Provide the REXX that produces your unexpected output. |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
| read the rexx manual pages that describe the overlay function |
|
| Back to top |
|
 |
hsrPulivarthi19
New User
Joined: 04 Mar 2021 Posts: 6 Location: India
|
|
|
|
Here is my rexx code:
GEN_NEW_JOB:
/*-----------*/
DO I=1 TO Njob.0
say 'before:' NJOB.I
posvar = 0 ; posvar= POS(Sjob,Njob.i)
IF POSvar > 0 then
njob.i = OVERLAY(JobNm,Njob.i,posvar)
posvar = 0 ; posvar= POS(SCMEM2,Njob.i)
IF POSvar > 0 then
njob.i = OVERLAY(NCMEM2,Njob.i,posvar)
posvar = 0 ; posvar= POS(SCMEM1,Njob.i)
IF POSvar > 0 then
njob.i = OVERLAY(NCMEM1,Njob.i,posvar)
say 'After: ' NJOB.I
END
Output:
before: // MEM1='GF010X',
After: // MEM1='CN110X',
before: // MEM2='GF010XC'
After: // MEM2='CN210XC'
Expected o/p:
before: // MEM1='GF010X',
After: // MEM1='CN1',
before: // MEM2='GF010XC'
After: // MEM2='CN2' |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
you might be
but you must achieve netter reading skills
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',<<< |
|
|
| Back to top |
|
 |
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 767 Location: Whitby, ON, Canada
|
|
|
|
| Have you considered using ISPF File Tailoring? It is specifically designed to merge user input from a panel with JCL in a skeleton. |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2286 Location: USA
|
|
|
|
My approach is always: use a simple tools to do a simple job.
When I need to hammer a nail, I use just a hammer, but do not try to develop any GPS-controlled robotic device with artificial intelligence.
For this extremely trivial task I suggest to use one of standard utilities, like SORT (also FileAid, and others are suitable)
| Code: |
SORT FIELDS=COPY
OUTFIL FINDREP=(INOUT=(C’GF010X’,C’CN1’,
C’GF010XC’,C’CN2’))
END |
That’s it... |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2286 Location: USA
|
|
|
|
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
|
That’s it, again... |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2286 Location: USA
|
|
|
|
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
|
|
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2286 Location: USA
|
|
|
|
When using any way of implementation, you MUST pay attention to: verify longer words before shorter ones, or not!
In your own example the word ‘CF010X’ will be replaced instead of ‘CF010XC’...
In my implementation examples I just followed your method of verification, it may be either correct, or wrong - depending on your actual requirements. |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2286 Location: USA
|
|
|
|
| sergeyken wrote: |
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. . . . . . . |
Also more simple function Word() can be used
| Code: |
CheckWord = Word( OldWords, i )
. . . . . . . Etc. . . . . . . . |
|
|
| Back to top |
|
 |
hsrPulivarthi19
New User
Joined: 04 Mar 2021 Posts: 6 Location: India
|
|
|
|
| enrico-sorichetti wrote: |
you might be
but you must achieve netter reading skills
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 |
|
| Back to top |
|
 |
hsrPulivarthi19
New User
Joined: 04 Mar 2021 Posts: 6 Location: India
|
|
|
|
| sergeyken wrote: |
| sergeyken wrote: |
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. . . . . . . |
Also more simple function Word() can be used
| Code: |
CheckWord = Word( OldWords, i )
. . . . . . . Etc. . . . . . . . |
|
Hi,
Thankyou for your suggestions.
Your code helped me to customize solution as per my requirement. This is the final code, which is giving my desired output.
PRETEXT=' ' ; POSTTEXT=' ';
if pos(srchstr,srcline) > 0 then
do
PARSE VAR srcline PRETEXT (srchstr) POSTTEXT
srcline = PRETEXT||replstr||POSTTEXT
end
Output:
before: //PN2G010X JOB CZXXX002,'YYYYYY',CLASS=J,REGION=0M,TIME=1440,
After: //GN2G010X JOB CZXXX002,'YYYYYY',CLASS=J,REGION=0M,TIME=1440,
before: // MEM1='GF010X',
After: // MEM1='CN1',
before: // MEM2='GF010XC'
After: // MEM2='CONTROL2'
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, |
|
| Back to top |
|
 |
hsrPulivarthi19
New User
Joined: 04 Mar 2021 Posts: 6 Location: India
|
|
|
|
| don.leahy wrote: |
| 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. |
|
| Back to top |
|
 |
hsrPulivarthi19
New User
Joined: 04 Mar 2021 Posts: 6 Location: India
|
|
|
|
| sergeyken wrote: |
When using any way of implementation, you MUST pay attention to: verify longer words before shorter ones, or not!
In your own example the word ‘CF010X’ will be replaced instead of ‘CF010XC’...
In my implementation examples I just followed your method of verification, it may be either correct, or wrong - depending on your actual requirements. |
What you said is true.
To resolve this, I had longer words check prior to the shorter words. |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2286 Location: USA
|
|
|
|
| Please, Learn how to use code tags in your messages! |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2286 Location: USA
|
|
|
|
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
|
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|