Variables
A variable is a character or group of characters representing a value. A variable can contain single- or double-byte characters, or both.
Double-byte characters are valid only if OPTIONS ETMODE is the first instruction of your program.
The following variable big represents the value one million or 1,000,000.
big = 1000000
Variables can refer to different values at different times. If you assign a different value to
big, it gets the value of the new assignment, until it is changed again.
big = 999999999
Variables can also represent a value that is unknown when the program is written. In the
following example, the user's name is unknown, so it is represented by the variable
who.
/* Gets name from current input stream */
PARSE PULL who /* and puts it in variable "who" */Variable names
A variable name, the part that represents the value, is always on the left of the assignment statement and the value itself is on the right.
In the following example, the variable name is variable1.
variable1 = 5
SAY variable1
As a result of the earlier assignment statement, the language processor assigns
variable1 the value
5 , and the SAY produces:
5
Variable names can consist of: the following characters:
- A - Z
- uppercase alphabetic
- a - z
- lowercase alphabetic
- 0 - 9
- numbers
- ? ! . _
- special characters
- X'41' - X'FE'
- double-byte character set (DBCS) charactersNote: Double-byte characters are valid only if OPTIONS ETMODE is the first instruction of your program.
The following restrictions apply to variable names:
- The first character cannot be 0 through 9 or a period (.)
- The variable name cannot exceed 250 bytes. For names containing DBCS characters, count each DBCS character as 2 bytes, and count the shift-out (SO) and shift-in (SI) as 1 byte each.
- SO (X'0E') and SI (X'0F') must delimit DBCS characters within a DBCS name. Also:
- SO and SI cannot be contiguous.
- Nesting of SO / SI is not permitted.
- A DBCS name cannot contain a DBCS blank (X'4040').
- The variable name should not be RC, SIGL, or RESULT, which are REXX special variables. See Special variables.
The following names are examples of acceptable variable
names:
ANSWER ?98B A Word3 number the_ultimate_valueAlso, if OPTIONS ETMODE is the first instruction in your program, the following are valid DBCS
variable names, where
< represents shift-out, > represents
shift-in, X, Y , and Z represent DBCS characters,
and lowercase letters and numbers represent
themselves.
<.X.Y.Z> number_<.X.Y.Z> <.X.Y>1234<.Z>
Variable values
The value of the variable, which is the value the variable name represents, might be categorized as follows:
- A constant , which is a number that is expressed as:
- An integer (12)
- A decimal (12.5)
- A floating point number (1.25E2)
- A signed number (-12)
- A string constant (' 12')
- A string , which is one or more words that may or may not be within quotation marks,
such as:
This value can be a string. 'This value is a literal string.' - The value from another variable , such as:
variable1 = variable2In the preceding example, variable1 changes to the value of variable2 , but variable2 remains the same.
- An expression , which is something that needs to be calculated, such as:
variable2 = 12 + 12 - .6 /* variable2 becomes 23.4 */
Before a variable is assigned a value, its value is the value of its own name translated to
uppercase. For example, if the variable new has not been assigned a value, then
SAY new produces NEW
Exercises: identifying valid variable names
Which of the following are valid REXX variable names?
- 8eight
- $25.00
- MixedCase
- nine_to_five
- result
ANSWERS
- Incorrect, because the first character is a number.
- Incorrect, because the first character is a currency symbol ($).
- Valid
- Valid
- Valid, but it is a special variable name that you should use only to receive results from a subroutine.
Note: The following characters might display differently in the
REXX online help depending on the code page used in your emulator configuration:
@ # $
¢. See also Conventions and terminology used in the CICS documentation.