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

TSO/E-REXX - parsing strings - could use some help


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

New User


Joined: 09 Dec 2005
Posts: 33

PostPosted: Wed May 09, 2007 5:33 pm
Reply with quote

hey all,

I'm trying to find a good method to parse data out of a long string - I usually use index and substr, but I think that PARSE would be a better alternative. Problem is, I don't know how to use parse properly for something like this.

examples of string that I want to analyze:
1)#JI,ID=32
2)#JI,ID=(10-23,29,31,32)
3)#JI,ID=(10-22)
4)#JI,ID=10
5)#JI,ID=(10,11,12,13,14,15,16,17,18,19,20,21,22)
6)#JI,ID=(29,31,32)

I want to extract the numbers from the above strings. They will be used as subscripts for a stem variable at a later point.
To continue the example, the desired output would be
1)sub.1=32
2)sub.1=10,
sub.2=11,
sub.3=12
....
sub.14=23
sub.15=29
sub.16=31
sub.17=32
... and so on...

I'm gonna go ahead and try use index,substr, and delstr but from what I've heard/read PARSE is a much better way to do this. Anybody feel like pointing me in the right direction?

much thanks

PS: yeah, I know converting the string "10-23" into a 14 element stem has to be done with programming logic and can't be done thru PARSE.
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Thu May 10, 2007 11:07 am
Reply with quote

Here is something to start with:
Code:
/* REXX */                                             
                                                       
STR = "#JI,ID=(10,11,12,13,14,15,16,17,18,19,20,21,22)"
                                                       
STR = TRANSLATE(STR,' ','#JI,ID=()')                   
                                                       
SAY STR                                                 
                                                       
EXIT                                                   
                                                       


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

New User


Joined: 09 Dec 2005
Posts: 33

PostPosted: Thu May 10, 2007 11:13 am
Reply with quote

thanks,

that's a good tip - it didn't even cross my mind to use translate.
Back to top
View user's profile Send private message
nuck

New User


Joined: 09 Dec 2005
Posts: 33

PostPosted: Thu May 10, 2007 11:28 am
Reply with quote

got it....

STR = "#JI,ID=(10,11,12,13,14,15,16,17,18,19,20,21-29)"

STR = TRANSLATE(STR,' ','#JI,ID=()')

SAY STR
cnt=0
do until str=''
cnt=cnt+1
parse var str shid.cnt str
say shid'.'cnt'='shid.cnt ' str=' str
end
EXIT

results in:
10 11 12 13 14 15 16 17 18 19 20 21-29
SHID.1=10 str= 11 12 13 14 15 16 17 18 19 20 21-29
SHID.2=11 str= 12 13 14 15 16 17 18 19 20 21-29
SHID.3=12 str= 13 14 15 16 17 18 19 20 21-29
SHID.4=13 str= 14 15 16 17 18 19 20 21-29
SHID.5=14 str= 15 16 17 18 19 20 21-29
SHID.6=15 str= 16 17 18 19 20 21-29
SHID.7=16 str= 17 18 19 20 21-29
SHID.8=17 str= 18 19 20 21-29
SHID.9=18 str= 19 20 21-29
SHID.10=19 str= 20 21-29
SHID.11=20 str= 21-29
SHID.12=21-29 str=
***

perfect!
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 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