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

FIND and REPLACE in REXX


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

New User


Joined: 13 Dec 2007
Posts: 11
Location: USA, California

PostPosted: Thu Sep 02, 2010 4:55 am
Reply with quote

Using REXX I've created a tool to set up a job to different region. But got stuck with one change. The source JCL has different printer name as destination. e.g. DEST=PRT505 and I have to change all the occurence as DEST=* but I don't have the list of occurences. So wildly I have to replace the printer name with *. Please help/suggest me to finish this. Thanks.
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Thu Sep 02, 2010 11:20 am
Reply with quote

Use the EDIT service with the MACRO option.

O.
Back to top
View user's profile Send private message
Kurt Deininger

New User


Joined: 13 Jul 2010
Posts: 19
Location: Frankfurt/Germany

PostPosted: Thu Sep 02, 2010 11:48 am
Reply with quote

Hi janaonline,

Try this one:

Code:
/* REXX */                                                             
   address tso "alloc fi(oldjcl) da("oldfile") shr reuse"               
   address tso "execio * diskr oldjcl (open stem jcl. finis)"           
   address tso "free fi(oldjcl)"                                       
   txt_old="DEST=PRT505"                                               
   lng_old=length(txt_old)                                             
   txt_new="DEST=*"                                                     
   do jcl_row=1 to jcl.0                                               
      jcl_lin=jcl.jcl_row                                               
      jcl_col=length(jcl_lin)                                           
      if jcl_col>0 then do                                             
         do forever                                                     
            jcl_col=lastpos(txt_old,jcl_lin,jcl_col)                   
            if jcl_col=0 then do                                       
               leave                                                   
               end                                                     
            jcl_lin=left(jcl_lin,jcl_col-1)txt_new !! ,                 
                    substr(jcl_lin,jcl_col+lng_old)                     
            end                                                         
         end                                                           
      jcl.jcl_row=jcl_lin                                               
      end                                                               
   address tso "alloc fi(newjcl) da("newfile") shr reuse"               
   address tso "execio * diskw newjcl (open stem jcl. finis)"           
   address tso "free fi(newjcl)"                                       
   exit 


Cheers Kurt

Amended post to use code tags
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Thu Sep 02, 2010 12:00 pm
Reply with quote

Kurt,

Please learn to use the code tags shown below
Code:
 [code] your stuff in here [/code]


Sorry, but I think that Ofer71 has given the best answer. A simple edit macro is far easier than reading and analysing every line of every member and processing them one by one.
Back to top
View user's profile Send private message
Kurt Deininger

New User


Joined: 13 Jul 2010
Posts: 19
Location: Frankfurt/Germany

PostPosted: Thu Sep 02, 2010 4:58 pm
Reply with quote

expat,

Thanks for the hint and for fixing the code. I admit Ofer71's
solution is better. He must have submitted it whilst I was coding
mine in between working. It's all good fun anyhow and I like the
site.

Cheers Kurt
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Thu Sep 02, 2010 5:00 pm
Reply with quote

Kurt,

All good contributers are most welcome
so keep up the good contributions icon_biggrin.gif
Back to top
View user's profile Send private message
janaonline

New User


Joined: 13 Dec 2007
Posts: 11
Location: USA, California

PostPosted: Sat Oct 23, 2010 12:42 am
Reply with quote

ofer71 wrote:
Use the EDIT service with the MACRO option.

O.


Thanks for your input. I have used the same to finish my program.

However this is only useful if we know what exactly to be searched and replaced.

For e.g

Code:


"ISREDIT C ALL 'DEST=ACCT07' 'DEST=LOCAL'"



Since i have the complete list of printer names, i could do finish it.

But question is, say i don't have the list of printer names and i have to wildly search for "DEST=" and replace the printer name with "LOCAL" irrespectively.

Thanks for your time.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Sat Oct 23, 2010 1:06 am
Reply with quote

If you are writing your edit macro in Rexx, you could use a combination of edit commands and Rexx to do the substitution, e.g.
Code:

address isredit "FIND DEST="

do while (rc=0)
  address isredit "(L1) = CURSOR"
  address isredit "(D1) = LINE &L1"
  p1 = pos("DEST=",d1)
  p2 = pos(",",d1,p1)
  d1 = substr(d1,1,p1-1) || "DEST=LOCAL," || substr(d1,p2+1)
  address isredit "LINE &L1 = (D1)"
  address isredit "FIND DEST="
end

(Note the assumption that the printer name is always delimited on the right by a comma which is not the last character on the line. Also, I wrote this "on the fly" and without testing it.)
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 Compile Several JCL JOB Through one r... CLIST & REXX 4
No new posts Replace each space in cobol string wi... COBOL Programming 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
Search our Forums:

Back to Top