What Is a Compound Variable?
You can use compound variables to create an array or a list of
variables in REXX. A
compound variable
, for example:
employee.1
,
consists of a stem and a tail. A
stem
is a symbol with a period
at the end. Here are some examples of stems:
FRED.
Array.
employee.
A
tail
is similar to a subscript. It
follows the stem and consists of additional parts of the name that
can be constant symbols (as in
employee.1
), simple
symbols (as in
employee.n
), or null. Thus, in REXX,
subscripts need not necessarily be numeric. A compound variable contains
at least one period with characters on both sides of it. Here are
some more examples of compound variables:
FRED.5
Array.Row.Col
employee.name.phone
You cannot do any substitution for the name of the stem but you
can use substitution for the tail. For example:
employee.7='Amy Martin'
new=7
employee.new='May Davis'
say employee.7 /* Produces: May Davis */
As
with other REXX variables, if you have not previously assigned a value
to a variable in a tail, it takes on the value of its own name in
uppercase.
first = 'Fred'
last = 'Higgins'
name = first.last /* NAME is assigned FIRST.Higgins */
/* The value FIRST appears because the */
/* variable FIRST is a stem, which */
/* cannot change. */
SAY name.first.middle.last /* Produces NAME.Fred.MIDDLE.Higgins */
You can use a DO loop to initialize a group of compound variables
and set up an array.
DO i = 1 TO 6
PARSE PULL employee.i
END
If you use the same names used in the example of the employee array,
you have a group of compound variables as follows:
employee.1 = 'Adams, Joe'
employee.2 = 'Crandall, Amy'
employee.3 = 'Devon, David'
employee.4 = 'Garrison, Donna'
employee.5 = 'Leone, Mary'
employee.6 = 'Sebastian, Isaac'
After the names are in
the group of compound variables, you can easily access a name by its
number or by a variable that represents its number.
name = 3
SAY employee.name /* Produces 'Devon, David' */
For more information about compound variables, see section Compound Symbols.