Assignments and symbols

A variable is an object whose value can change during the running of a REXX program. The process of changing the value of a variable is called assigning a new value to it. The value of a variable is a single character string, of any length, that might contain any characters.

You can assign a new value to a variable with the ARG, PARSE, or PULL instructions, the VALUE built-in function, or the Variable Access Routine (IRXEXCOM), but the most common way of changing the value of a variable is the assignment instruction itself. Any clause of the form:

symbol=expression;
is taken to be an assignment. The result of expression becomes the new value of the variable named by the symbol to the left of the equal sign. On TSO/E, if you omit expression, the variable is set to the null string. However, it is suggested that you explicitly set a variable to the null string: symbol=''.

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

Variable names can contain DBCS characters. For information about DBCS characters, see Double-byte character set (DBCS) support.

Example:
/* Next line gives FRED the value "Frederic" */
Fred='Frederic'

The symbol naming the variable cannot begin with a digit (09) or a period. (Without this restriction on the first character of a variable name, you could redefine a number; for example 3=4; would give a variable called 3 the value 4.)

You can use a symbol in an expression even if you have not assigned it a value, because a symbol has a defined value at all times. A variable you have not assigned a value is uninitialized. Its value is the characters of the symbol itself, translated to uppercase (that is, lowercase az to uppercase AZ). However, if it is a compound symbol (described under Compound symbols), its value is the derived name of the symbol.

Example:
/* If Freda has not yet been assigned a value,   */
/* then next line gives FRED the value "FREDA"   */
Fred=Freda

The meaning of a symbol in REXX varies according to its context. As a term in an expression (rather than a keyword of some kind, for example), a symbol belongs to one of four groups: constant symbols, simple symbols, compound symbols, and stems. Constant symbols cannot be assigned new values. You can use simple symbols for variables where the name corresponds to a single value. You can use compound symbols and stems for more complex collections of variables, such as arrays and lists.