Assignment Statements
Assignment statements give values to variables and do arithmetic operations within a command list. An assignment statement has the following syntax:
A blank must be before and after the equal sign.
When the command list runs, the value of the user variable is set to the value of the expression. For example, the assignment statement &A = 5 sets the &A to 5. The assignment statement &B = &1 sets the &B to the value of &1, and &1 keeps its value.
- Constant
- A constant
consists of alphanumeric characters that are not replaced by other
values. The values are fixed. For example, if you code the following
assignment statement:
the value 5 is assigned to user variable &VAR.&VAR = 5If you want to use a constant that contains a blank, comma, apostrophe, or hyphen, use single quotation marks. For example:&NAME = 'JOHN B. DOE'The constant cannot be longer than 255 characters. If it is a number, the constant must be between -2147483647 and 2147483647. The only characters you can have in a numeric value are 0-9. The numeric value can be immediately preceded by a character indicating whether the value is positive (+) or negative (-).
- Variable
- A variable can be a parameter variable, control variable, user
variable, or global variable. The following assignment statement:
assigns the value of parameter variable &4 to user variable &PARMVAR.&PARMVAR = &4To assign the value of control variable &OPID to user variable &USERVAR, code the following statement:&USERVAR = &OPIDNote: Using a control statement as a variable is not valid, even if the control statement is enclosed in single quotation marks. For example, the following assignment statements are not valid:&A = &IF &A = '&WAIT ERROR' - Arithmetic operation
- The
addition and subtraction operations are allowed in an assignment statement.
The format is two numbers separated by a plus (+) or minus (-) sign.
You can also use a variable that is to be set to a number. The only
characters you can use in a numeric value are 0-9. The numeric value
can be immediately preceded by a character indicating whether the
value is positive (+) or negative (-).
The plus or minus sign must be separated from the numbers on each side by at least one blank unless it indicates a positive or negative number (-2, -4). For example, both 4 - 2 and 4 - -2 are correct, but 4 -2 does not work.
The result of the arithmetic operation must be between -2147483647 and 2147483647. The following assignment statement shows how you can use a control variable in an arithmetic operation:
The value of control variable &PARMCNT is subtracted from 38, and the resulting value is assigned to variable &SUM.&SUM = 38 - &PARMCNTIn arithmetic expressions with leading zeros, the leading zeros are not shown in the result. For example, assume &A is 01 and you code the following statement:
The value of &C becomes 2, not 02.&C = &A + 1Note: To avoid an error condition in an arithmetic operation, code a zero before a potential null variable. - Built-in function
- You can use a built-in
function in an assignment statement. The
result of the operation is placed in the user variable. See NetView Built-in Functions for a detailed description.
The following examples show how to code built-in functions in assignment statements:
&STR2 = &SUBSTR &STRING 2 1 &STR1 = &SUBSTR &STRING 1 1 &NEWSTR = &CONCAT &STR5 &STR4 &NEWSTR = &CONCAT &NEWSTR &STR3
