z/OS TSO/E REXX Reference
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Compound symbols

z/OS TSO/E REXX Reference
SA32-0972-00

A compound symbol permits the substitution of variables within its name when you refer to it. A compound symbol contains at least one period and at least two other characters. It cannot start with a digit or a period, and if there is only one period in the compound symbol, it cannot be the last character.

The name begins with a stem (that part of the symbol up to and including the first period). This is followed by a tail, parts of the name (delimited by periods) that are constant symbols, simple symbols, or null. The derived name of a compound symbol is the stem of the symbol, in uppercase, followed by the tail, in which all simple symbols have been replaced with their values. A tail itself can be comprised of the characters A–Z, a–z, 0–9, and @ # $ ¢ . ! ? and underscore. The value of a tail can be any character string, including the null string and strings containing blanks. For example:
taila='* ('
tailb=''
stem.taila=99
stem.tailb=stem.taila
say stem.tailb        /* Displays: 99                 */
/* But the following instruction would cause an error */
/*         say stem.* (                               */

You cannot use constant symbols with embedded signs (for example, 12.3E+5) after a stem; in this case, the whole symbol would not be a valid symbol.

These are compound symbols:
FRED.3
Array.I.J
AMESSY..One.2.

Before the symbol is used (that is, at the time of reference), the language processor substitutes the values of any simple symbols in the tail (I, J, and One in the examples), thus generating a new, derived name. This derived name is then used just like a simple symbol. That is, its value is by default the derived name, or (if it has been used as the target of an assignment) its value is the value of the variable named by the derived name.

The substitution into the symbol that takes place permits arbitrary indexing (subscripting) of collections of variables that have a common stem. Note that the values substituted can contain any characters (including periods and blanks). Substitution is done only one time.

To summarize: the derived name of a compound variable that is referred to by the symbol
s0.s1.s2. --- .sn
is given by
d0.v1.v2. --- .vn
where d0 is the uppercase form of the symbol s0, and v1 to vn are the values of the constant or simple symbols s1 through sn. Any of the symbols s1-sn can be null. The values v1-vn can also be null and can contain any characters (in particular, lowercase characters are not translated to uppercase, blanks are not removed, and periods have no special significance).
Some examples follow in the form of a small extract from a REXX program:
a=3       /* assigns '3' to the variable A    */
z=4                 /*   '4'      to Z        */
c='Fred'            /*   'Fred'   to C        */
a.z='Fred'          /*   'Fred'   to A.4      */
a.fred=5            /*   '5'      to A.FRED   */
a.c='Bill'          /*   'Bill'   to A.Fred   */
c.c=a.fred          /*   '5'      to C.Fred   */
y.a.z='Annie'       /*   'Annie'  to Y.3.4    */

say  a  z  c  a.a  a.z  a.c  c.a  a.fred y.a.4
/* displays the string:                     */
/*    "3 4 Fred A.3 Fred Bill C.3 5 Annie"  */

You can use compound symbols to set up arrays and lists of variables in which the subscript is not necessarily numeric, thus offering great scope for the creative programmer. A useful application is to set up an array in which the subscripts are taken from the value of one or more variables, effecting a form of associative memory (content addressable).

Implementation maximum: The length of a variable name, before and after substitution, cannot exceed 250 characters.

REXX symbol and hexadecimal code cross-reference shows the REXX symbols and their hexadecimal values as found in the U.S. Code Page (037).

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014