View previous topic :: View next topic
|
Author |
Message |
srinivasbathimmi
New User
Joined: 10 May 2006 Posts: 13
|
|
|
|
Can any one help me out.
My requirement is, I have to replace the string '@@@' to something in all PDS Members. For this requirement I have written a REXX program. Please find the below piece of code that is not working properly.
Code: |
DO J = 1 TO PRG1.0
IF POS('$$$',PRG1.J) > 0 THEN
DO
SAY PRG1.J
SAY SUBSTR(ARR1.I,1,3)
PRG1.J = TRANSLATE(PRG1.J,SUBSTR(ARR1.I,1,3),'@@@')
SAY PRG1.J
END
END |
When I display SUBSTR(ARR1.I,1,3), it is giving correct values.
The problem is with the TRANSLATE command.
TRANSLATE command is replacing '@@@' with the wrong value.
For example : If I give like replace '@@@' with 'ABC'
output is giving like 'AAA' instead of 'ABC'.
(ie; it is replacing whole string with first character of desired string).
I want output as 'ABC' after translate command.
Please let me know why TRANSLATE is not working in this situation? or is there any other command I can use for this requirement?
Regards,
Srinivas. |
|
Back to top |
|
|
PeD
Active User
Joined: 26 Nov 2005 Posts: 459 Location: Belgium
|
|
|
|
Process as you need
and when accurate ( meaning when @@@ is on the line )
override that value using overlay
PRG1.J = Overlay('ABC',PRG1.J,Index(PRG1.J,'@@@'),3)
Be sure Index(PRG1.J) is > 0.
( not tested )
Cheers
Pierre |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
translate works at byte(char) level,,,
itable = "@@@"
otable = "abc"
rexx logic is to scan the input table and substitute in the output string
the character of the output table which is in the same relative position...
so the first occurence of @ will be used to index the output table |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2546 Location: Silicon Valley
|
|
|
|
Your program needs to detect if there are multiple instances of the search string. In your sample program, it only checks for 1 and then goes to the next line. |
|
Back to top |
|
|
srinivasbathimmi
New User
Joined: 10 May 2006 Posts: 13
|
|
|
|
The below one is working fine.
PRG1.J = Overlay('ABC',PRG1.J,Index(PRG1.J,'@@@'),3)
The above Overlay command is replacing '@@@' with 'ABC' for the first occurance only. Could you please let me know how to replace all occurances of '@@@' to 'ABC'.
Regards,
Srinivas. |
|
Back to top |
|
|
PeD
Active User
Joined: 26 Nov 2005 Posts: 459 Location: Belgium
|
|
|
|
something like
For every line PRG1 ( sequentially read or in a loop 'J' )
Do While Index(PRG1.J,'@@@') > 0
overlay statement
End
No? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
why not use an edit macro???
look at
ibmmainframes.com/viewtopic.php?t=25947&highlight=
for a macro that applies a macro to all the members of a pds
and the inner macro would look like
Code: |
/*REXX - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* $CHANGE */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
Trace "O"
Parse Source _system _called _commnd .
If Sysvar(SYSISPF) /= "ACTIVE" Then Do
Say left(_commnd,8)"- Ispf is not active. Command not executed"
Exit 4
End
call $init_
call $ispex "CONTROL ERRORS RETURN"
if $isred("MACRO (ZPARMS) NOPROCESS ") = 0 then do
_parms = strip(translate(zparms))
end
else do
zerrsm = "Invocation ERROR"
zerrlm = left(_commnd,8)"- Must be invoked as an edit macro"
call $ispex "SETMSG MSG(ISRZ002) "
Exit 1
end
call $isred "CHANGE '@@@' 'zzz' ALL"
call $isred "END"
Exit
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$init_:
ini_0tr = trace("O")
zerralrm = "YES"
zerrhm = "ISR2MACR"
ini_0rc = 0
trace value(ini_0tr)
return ini_0rc
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$tsoex:
tso_0tr = trace("O")
Address TSO arg(1)
tso_0rc = rc
trace value(tso_0tr)
return tso_0rc
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$ispex:
isp_0tr = trace("O")
Address ISPEXEC arg(1)
isp_0rc = rc
trace value(isp_0tr)
return isp_0rc
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$isred:
isr_0tr = trace("O")
Address ISREDIT arg(1)
isr_0rc = rc
trace value(isr_0tr)
return isr_0rc
|
should work for You |
|
Back to top |
|
|
srinivasbathimmi
New User
Joined: 10 May 2006 Posts: 13
|
|
|
|
Ped,
As per your suggestion I have modifed the code as below, it is going to infinite loop can you please check it once.
DO J = 1 TO PRG1.0
IF POS('$$$',PRG1.J) > 0 THEN
DO
DO WHILE INDEX(PRG1.J,'$$$') > 0
PRG2.K = OVERLAY(ARR1.I,PRG1.J,INDEX(PRG1.J,'$$$'),3)
END
K = K + 1
END
ELSE
DO
PRG2.K = PRG1.J
K = K + 1
END
Could you please help me out. |
|
Back to top |
|
|
PeD
Active User
Joined: 26 Nov 2005 Posts: 459 Location: Belgium
|
|
|
|
DO J = 1 TO PRG1.0
DO WHILE INDEX(PRG1.J,'$$$') > 0
PRG1.J = OVERLAY(ARR1.I,PRG1.J,INDEX(PRG1.J,'$$$'),3)
END
??? tft to PRG2.n ????
END |
|
Back to top |
|
|
|