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

Dynamic variable name in REXX


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

New User


Joined: 05 Feb 2007
Posts: 61
Location: Chennai

PostPosted: Tue Oct 05, 2010 11:14 am
Reply with quote

Hi,

My REXX program will create count of various search results and puts the counts say CNT1,CNT2, CNT3 etc.

Now, I want to display these counts using SAY and I don't know how many counts would be there.

For displaying these counts, I want to use a loop instead of SAY for each count variable.

Please let me know how to achieve this.
I am using the below loop and not working.

DO J = 1 TO 10
SAY 'COUNT ' J CNT!!J
END
Back to top
View user's profile Send private message
expat

Global Moderator


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

PostPosted: Tue Oct 05, 2010 11:23 am
Reply with quote

Use a STEM variable
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Oct 05, 2010 11:31 am
Reply with quote

why not use a stem and have stem.0 contain the number of entries?
as an alternative use the interpret instruction , but it needs more mastering skills

here is a sample of both approaches
Code:

trace "O"
parse arg k
if k > 8 then ,
   exit

say "filling  the vars "
do i = 1 to k
   say "name"i "= "i
   interpret "name"i "= "i
end

say "showing what is there and what is not"
say "name1" name1
say "name2" name2
say "name3" name3
say "name4" name4
say "name5" name5
say "name6" name6
say "name7" name7
say "name8" name8

say "showing the vars "
do i = 1 to k
   say "temp = name"i
   interpret "temp = name"i
   say "name"i temp
end


stem.0 = k
do i = 1 to k
   stem.i = i
end

k = stem.0
do i  = 1 to k
   say "stem."i stem.i
end

exit


but working with INTERPRET might become quite painful, it' s not easy to decide at a glance what should be inside and outside quotes/apost's
a good way to debug INTERPRET issues is to precede it with a SAY instruction with the same right part ,
in this way You will see exactly what is going to be interpreted
Back to top
View user's profile Send private message
hariibm

New User


Joined: 05 Feb 2007
Posts: 61
Location: Chennai

PostPosted: Tue Oct 05, 2010 11:40 am
Reply with quote

Thanks expat and enrico.

Thanks especially for the introducing the INTERPRET option for me.
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Tue Oct 05, 2010 4:03 pm
Reply with quote

another option...

if CNT1,CNT2, CNT3 are already populated...

Code:
cnt1=100   
cnt2=200   
cnt3=300   


you can use the builtin VALUE instead of interpret

Code:
do i = 1 to 3                 
   temp=value("cnt"i)       
   say temp                   
   end i
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Tue Oct 05, 2010 4:12 pm
Reply with quote

btw, in the example above I woud go for a stem, was just trying to show an option to INTERPRET.
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
Search our Forums:

Back to Top