View previous topic :: View next topic |
Author |
Message |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Tue Jan 07, 2003 2:15 am Post subject: Multi dimensional Array Concept |
|
|
Hi,
I want to store the member names of different PDS in an 2 dimension array(Stem). But I don't know whether we have the concept of multi dimensional (Stem/Array) in Rexx. I solved this problem in a different way (without using arrays at all) but I'm very much interested in knowing whether we have this feature in Rexx or not. (Note : I don't want to store the entire list in a single array, though we can do it ).
Please Advise
Thanks & Regards,
Navin. J |
|
Back to top |
|
 |
raj051076 Beginner
Joined: 05 Dec 2002 Posts: 64 Topics: 21
|
Posted: Tue Jan 07, 2003 2:26 am Post subject: |
|
|
As far as my knowledge goes there is no multidimensional array in REXX but you can have a work around to get the flavor of multi dimension _________________ Rajib |
|
Back to top |
|
 |
DaveyC Moderator

Joined: 02 Dec 2002 Posts: 151 Topics: 3 Location: Perth, Western Australia
|
Posted: Tue Jan 07, 2003 9:18 am Post subject: |
|
|
you can have much more than multi dimension arrays in REXX. Compound variables can be used as a psueudo hash table, you name it.
Code: |
/* array with two dimensions */
array. = 0
do i = 1 to 10
do j = 1 to 10
array.i.j = 1
end
end
|
Watch out for side effects when using compound variables. _________________ Dave Crayford |
|
Back to top |
|
 |
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Tue Jan 07, 2003 9:33 am Post subject: |
|
|
In addition to what Dave posted above, the following is also possible.
Code: |
first ='Fred'
last ='Higgins'
employee =first.last
/*EMPLOYEE is assigned FIRST.Higgins */
SAY employee.first.middle.last
/*Displays EMPLOYEE.Fred.MIDDLE.Higgins */
|
_________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
 |
raj051076 Beginner
Joined: 05 Dec 2002 Posts: 64 Topics: 21
|
Posted: Tue Jan 07, 2003 10:59 am Post subject: |
|
|
Thanks Dave and Cognito learnt a new thing..will try it sometimes. _________________ Rajib |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Wed Jan 08, 2003 12:44 am Post subject: |
|
|
Dave & Cogito Thanks for Your suggestions. They are really great.
In the mean time, I tried to solve the problem in a different way without using arrays. I think you must be knowing this. Just have a look at this. Here I created a list of Tables with names as the Major Index of the Array (ie. Suppose we reference the array as A(I, J) then the names of tables would be the values stored in 'I' variable and the elements of the Tables will indexed by the value corresponding to the 'J' variable).
J = 1
CALL CREATE_TABLE J
J = J + 1
CALL CREATE_TABLE J
SAY 'TWO TABLES CREATED'
J = 1
DO I = 1 TO 10
CALL ADD_TO_TABLE J, I
END
J = J + 1
DO I = 11 TO 15
CALL ADD_TO_TABLE J, I
END
J = 1
CALL DISPLAY_TABLE_ELEMENTS J
J = J + 1
CALL DISPLAY_TABLE_ELEMENTS J
J = 1
CALL CLOSE_TABLE J
J = J + 1
CALL CLOSE_TABLE J
EXIT 0
CREATE_TABLE:
ARG TABLENAME
"ISPEXEC TBCREATE "TABLENAME" NAMES(SNO)"
RETURN
ADD_TO_TABLE:
ARG TABLENAME, VALUE
SNO = VALUE
"ISPEXEC TBADD "TABLENAME
RETURN
DISPLAY_TABLE_ELEMENTS:
ARG TABLENAME
"ISPEXEC TBTOP "TABLENAME
"ISPEXEC TBSTATS "TABLENAME" ROWCURR(RCOUNT)"
DO I = 1 TO RCOUNT
"ISPEXEC TBSKIP "TABLENAME" NUMBER(+1)"
"ISPEXEC TBGET "TABLENAME
SAY "("I")" SNO
END
SAY RCOUNT
RETURN
CLOSE_TABLE:
ARG TABLENAME
"ISPEXEC TBEND "TABLENAME
RETURN
Thank you very much for your valuable suggestions.
Navin. J |
|
Back to top |
|
 |
semigeezer Supermod
Joined: 03 Jan 2003 Posts: 1014 Topics: 13 Location: Atlantis
|
Posted: Wed Jan 08, 2003 1:16 am Post subject: |
|
|
That may be a good solution (I didn't examine it closely) because ISPF can not use stem variables. The period already has another meaning in ISPF elements (panels, messages, etc). But learing to use stem variables is really important because they can be used as hash tables. |
|
Back to top |
|
 |
DaveyC Moderator

Joined: 02 Dec 2002 Posts: 151 Topics: 3 Location: Perth, Western Australia
|
Posted: Wed Jan 08, 2003 8:24 am Post subject: |
|
|
As a short and sweet example of hash type lookups with compound variables:
Code: |
/* REXX to demonstrate hashing */
arg dataset
members. = 0
call outtrap "listds."
"LISTDS "dataset" M"
do i = 7 to listds.0
mem = strip( listds.i )
members.mem = 1
end
say "Search a PDS for a member..."
do forever
say "Enter a member name. 'Q' to quit"
pull parm
select
when parm = 'Q' then leave
when members.parm then say "member "parm" found"
otherwise say "member "parm" not found"
end
end
|
REXX is a cool language. It has it's good and bad points but I like it a lot... _________________ Dave Crayford |
|
Back to top |
|
 |
Mike Beginner

Joined: 03 Dec 2002 Posts: 114 Topics: 0 Location: Sydney, Australia
|
Posted: Wed Jan 08, 2003 4:37 pm Post subject: |
|
|
Dave,
I get around the 'side effects' of what I'll call multiple stems/tails by using interpret. e.g.
INTERPRET part1"."part2"."part3" = 'blah blah blah'"
where part1/2 &3 3 are appropriate variables. I always mean to really look into the 'side effects' and suss out what really happening.
Probably frowned upon by many but it works for me, it does make the code a little hard to understand though.
Regards,
Mike. _________________ Regards,
Mike. |
|
Back to top |
|
 |
semigeezer Supermod
Joined: 03 Jan 2003 Posts: 1014 Topics: 13 Location: Atlantis
|
Posted: Wed Jan 08, 2003 7:27 pm Post subject: |
|
|
Or you can call the value() function to do the assignment. I prefer that over interpret, but it is just a style thing. |
|
Back to top |
|
 |
DaveyC Moderator

Joined: 02 Dec 2002 Posts: 151 Topics: 3 Location: Perth, Western Australia
|
Posted: Wed Jan 08, 2003 9:58 pm Post subject: |
|
|
I picked up a tip using naming conventions.
Code: |
gbl.0_color = 'BLUE'
gbl.0_hilite = 'REVERSE'
0_color = 'ERROR' /* fails */
|
you cannot use variables in REXX that are prefixed by a numeric. I know it's very ugly but it's "safe"... In a large program it may be a good idea. Compound variables are a good way to use global variables in REXX, all you need to do is expose the stem name in the procedure. _________________ Dave Crayford |
|
Back to top |
|
 |
|
|