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

Help needed to search and insert a string using 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: Tue Jul 08, 2008 7:10 pm
Reply with quote

I need REXX code which does the following:

1. Search a string in all the members
2. If the string is found in any of the member then need to insert a string before the searched string.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jul 08, 2008 7:21 pm
Reply with quote

help yourself.

use the search. I know that there are several examples of search all members.

the insert:

after a find hit:

(workline) = linenum .zcsr

insert <yourstuff> before workline
Back to top
View user's profile Send private message
janaonline

New User


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

PostPosted: Tue Jul 08, 2008 7:25 pm
Reply with quote

Thanks for your immediate reply.

IF VAR3 = 'BEFORE' THEN
DO
I = 1
DO K = 1 TO CONTENTS.0
IF POS( VAR1 , CONTENTS.K) > 0 THEN DO
FOUND = 'Y'
OUTPUT.I = VAR2
I = I + 1
END
OUTPUT.I = CONTENTS.K
I = I + 1
END
END

the above code will insert the string as a separate line, but i need it to insert just before the searched string. Could you please help in this??

Thanks!!!
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jul 08, 2008 7:54 pm
Reply with quote

you can do this two ways.

1. use execio to read and write the records for the member. this way you would use stems (as your example). I have no suggestion for this, I would not do it this way.

2. use edit macro commands and have your rexx invoke each member via EDIT, then do your FIND, determine line no of hit, insert before lineno. restart you search at lineno + 1 (you insert a line before line 10, line 10 becomes line 11. if you don't start at line 12, you will be in a loop, finding things on the old line 10 -now 11- and inserting again.)
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Tue Jul 08, 2008 8:24 pm
Reply with quote

If you want to stick with using EXECIO instead of an edit macro (which DOES look to be the better option here), you might go with this:

var1 is the search string
var2 is the insertion string

Code:

  "EXECIO * DISKR ddname (STEM contents. FINIS"     
  Do i = 1 To contents.0                       
    If Pos(var1,contents.i) <> 0 Then         
      Do                                       
        Queue var2                             
        Queue contents.i                       
      End                                     
    Else Queue contents.i                     
  End                                         
  "EXECIO "Queued()" DISKW ddname (FINIS"
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Jul 08, 2008 8:46 pm
Reply with quote

here is a thread with a bit of string manipulation...
http://ibmmainframes.com/viewtopic.php?t=31958&highlight=substr
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jul 08, 2008 8:47 pm
Reply with quote

Kevin,

I have failed to say this before, but, you give good advice and your code is clean.
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Tue Jul 08, 2008 8:55 pm
Reply with quote

Thanks for the kind words. Maybe I should let my boss read this? icon_wink.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Jul 08, 2008 8:57 pm
Reply with quote

Quote:
Maybe I should let my boss read this?


Nahhh.....
he might complain that You spend too much time surfing the net icon_wink.gif
Back to top
View user's profile Send private message
janaonline

New User


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

PostPosted: Tue Jul 15, 2008 6:52 pm
Reply with quote

Thanks a lot for all your suggestion. That was really helpful..
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 PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Running REXX through JOB CLIST & REXX 13
No new posts Error to read log with rexx CLIST & REXX 11
Search our Forums:

Back to Top