IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

TRANSLATE command in REXX


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
srinivasbathimmi

New User


Joined: 10 May 2006
Posts: 13

PostPosted: Thu Nov 13, 2008 5:52 pm
Reply with quote

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
View user's profile Send private message
PeD

Active User


Joined: 26 Nov 2005
Posts: 459
Location: Belgium

PostPosted: Thu Nov 13, 2008 6:11 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Thu Nov 13, 2008 6:14 pm
Reply with quote

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
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2546
Location: Silicon Valley

PostPosted: Thu Nov 13, 2008 10:38 pm
Reply with quote

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
View user's profile Send private message
srinivasbathimmi

New User


Joined: 10 May 2006
Posts: 13

PostPosted: Fri Nov 14, 2008 10:58 am
Reply with quote

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
View user's profile Send private message
PeD

Active User


Joined: 26 Nov 2005
Posts: 459
Location: Belgium

PostPosted: Fri Nov 14, 2008 12:25 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Fri Nov 14, 2008 12:49 pm
Reply with quote

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
View user's profile Send private message
srinivasbathimmi

New User


Joined: 10 May 2006
Posts: 13

PostPosted: Fri Nov 14, 2008 1:05 pm
Reply with quote

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
View user's profile Send private message
PeD

Active User


Joined: 26 Nov 2005
Posts: 459
Location: Belgium

PostPosted: Fri Nov 14, 2008 1:13 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts RACF - Rebuild SETROPTS command which... All Other Mainframe Topics 3
No new posts Running REXX through JOB CLIST & REXX 13
No new posts Error to read log with rexx CLIST & REXX 11
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
No new posts run rexx code with jcl CLIST & REXX 15
Search our Forums:

Back to Top