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
 

 

Dynamic variable name in REXX

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
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    Post subject: Dynamic variable name in REXX
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: 8593
Location: Back in jolly old England

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

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

Global Moderator


Joined: 14 Mar 2007
Posts: 10274
Location: italy

PostPosted: Tue Oct 05, 2010 11:31 am    Post subject: Reply to: Dynamic variable name in REXX
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    Post subject:
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    Post subject: Reply to: Dynamic variable name in REXX
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    Post subject: Reply to: Dynamic variable name in REXX
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    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 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
No new posts REXX - Dynamic file Creation d_sarlie CLIST & REXX 7 Tue Jun 27, 2017 7:30 pm
No new posts REXX WTO for console message bipinpeter CLIST & REXX 6 Tue Jun 27, 2017 3:56 pm
No new posts Convert CLIST to REXX cvnlynn CLIST & REXX 12 Tue Jun 27, 2017 2:06 am


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