Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

FIND and REPLACE in REXX

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
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    Post subject: FIND and REPLACE in REXX
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: 2360
Location: Israel

PostPosted: Thu Sep 02, 2010 11:20 am    Post subject:
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    Post subject:
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: 8593
Location: Back in jolly old England

PostPosted: Thu Sep 02, 2010 12:00 pm    Post subject:
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    Post subject:
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: 8593
Location: Back in jolly old England

PostPosted: Thu Sep 02, 2010 5:00 pm    Post subject:
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    Post subject:
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: 1771
Location: Bloomington, IL

PostPosted: Sat Oct 23, 2010 1:06 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts I want to retire TRX and use only Rex... Abhinav Sharma CLIST & REXX 4 Sat Jul 29, 2017 2:53 am
No new posts Iterative use of a REXX script causin... bryonyh CLIST & REXX 4 Fri Jul 28, 2017 12:52 pm
No new posts Passing data from REXX to C programme... chong.zhou CLIST & REXX 3 Wed Jul 26, 2017 9:11 pm
No new posts REXX to get the all datasets name parasmalik20 CLIST & REXX 5 Tue Jul 18, 2017 9:10 pm
No new posts How system know which REXX to excute? jackzhang75 CLIST & REXX 14 Thu Jul 06, 2017 1:09 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us