I just want to add a bit more to the answer given by Deuian.
I agree, REXX stem variables
are the answer.
Simple REXX variables default to their own name. For example:
/* REXX */
SAY X
will print "X" until X
is assigned some other value:
/* REXX */
X = 'A'
SAY X
will print "A".
No big surprise so far. Stem variables are a bit different. The
head of the stem is never evaluated, only the bit after the initial dot
is.
To illustrate:
/* REXX */
X. = 'empty' /* all unassigned stem values take on this value */
A. = 'nil'
B = 'A' /* simple variable B is assigned value A */
X = 'A' /* simple variable X is assigned value A */
SAY X.A /* prints: empty */
X.A = 'hello' /* Stem X. associates value of A with 'hello' */
SAY X.A /* prints: hello */
SAY X.B /* prints: hello */
SAY X.X /* prints: hello */
Notice the X
and the A
stem names are not evaluated, however, the
X
and A
variables appearing after them are. Some people find this a
bit confusing - think about it for a while and it makes
great sense.
The Z/OS version of REXX does not provide a natural way to iterate over
a stem variable. The easiest way to do this is to build your own index.
For example:
/* REXX */
X. = ''
DO I = 1 TO 10
J = RANDOM(100, 500) /* Random # 100..500 */
X.INDEX = X.INDEX J /* concatinate J's with 1 space between */
X.J = 'was picked' /* Associate 'was picked' with whatever J evalauates to */
END
DO I = 1 TO WORDS(X.INDEX) /* Number of blank delimited 'words' */
J = WORD(X.INDEX, I) /* Extract 1 'word' at a time */
SAY J X.J /* Print 'word' and its associated value */
END
Pretty trivial but illustrates the idea. Just be sure that INDEX
(or whatever name you
choose) to hold the indexing names never pops up as an associative value! If this is a possibility, use some other variable to hold the index.
Last point. Notice each of my examples begins with /* REXX */
you may find
that this needs to be the first line of your REXX programs under Z/OS.