You can assign values to a variable to be used by a prompt. You can assign
a variable a specific value, the result of an arithmetic operation, or the
result of a function.
A variable might need a specific value before a statement can be successfully
executed, or you might need to assign the value of one variable to another
variable.
Arithmetic operations
- Add (+)
- Adds two values. The sum is assigned to your variable.
- Subtract (-)
- Subtracts the second value from the first. The difference is assigned
to your variable.
- Multiply (*)
- Multiplies two values. The product is assigned to your variable.
- Divide (/)
- Divides the first value by the second value. The result is assigned
to your variable. If the second value is zero, the result is Overflow.
- Modulus (%)
- Divides the first value by the second value, the remainder is assigned
to your variable. Both values must be integers, or the result is Data Mismatch.
For example, if the first value is 10 and second value is 3, the Modulus operation
calculates 10 divided by 3 = 3 remainder 1. A value of 1 is assigned to your
variable.
If the second value is zero, the result is Overflow.
Functions
- Absolute.
- Assigns the absolute value of a number to your variable.
For example,
if the value is -5, the value 5 is assigned to your variable.
- Round.
- Rounds the value at the digit specified by position. The rounded
value is assigned to your variable. Position must be an integer,
or else the result is Data Mismatch.
Round operates on numbers. If position is positive, the number is rounded at that digit place to the
right of the decimal place. If position is negative, the number is
rounded at that digit place to the left of the decimal place. Numbers ending
in 5 are rounded to the next higher value.
For example, if the value
is 135.789 and position is 1, the value 135.8 is assigned to your
variable. If position is -1, the value 140 is assigned. If position is 0, the value 136 is assigned.
- Truncate.
- Truncates the value of
your number at the digit specified by the position. The truncated
value is assigned to your variable. Position must be an integer,
or the result is a Data Mismatch.
Truncate operates on numbers. If position is positive, the number is truncated at that digit place to
the right of the decimal place. If position is negative, the number
is rounded down at that digit place to the left of the decimal place.
For example, if the number is 345.678 and position is 1, the value
345.6 is assigned to your variable. If position is -1, the value
340 is assigned. If position is 0, the value 345 is assigned.
- Concatenate.
- Appends the second string to the first string and assigns the new string to your
variable.
Concatenate is a string operation. If the first string is
a constant number, it is treated as a string, not a mathematical value.
- Index.
- Selects a character in string and assigns it to your variable.
The characters in string are numbered from left to right, starting
at 1. The character is selected by the number in position. If the
number position in points beyond either end of the string, then the
result will be an empty string.
For example, if string is 4085551212
and position is 3, the value 8 is assigned to your variable.
Index is a string operation. If string is a number, it is treated
as a string, not a numeric value.
- Length.
- Counts the number of characters
in string and assigns the result to your variable.
LENGTH is a
string operation. If string is a number, it is treated as a string,
not a numeric value.
- Left.
- Starts at the left-hand character
in string and counts over the number of characters in num_characters. The resulting string is assigned to your variable.
For example, if string is “caller” and num_characters is 4, the value
assigned to your variable is “call.”
Left is a string operation.
If string is a number, it is treated as a string, not a numeric value.
- Right.
- Starts at the right-hand
character in string and counts over the number of characters in num_characters. The resulting string is assigned to your variable.
For example, if string is “telephone” and num_characters is 5, the value “phone“ is assigned to your variable.
Right is a string operation. If string is a number, it is treated
as a string, not a numeric value.
- Search.
- Searches string for search_pattern (a shorter string). If the search pattern
is found, the position of the start of search_pattern in string is assigned to your variable. If search_pattern is
not found, 0 is assigned to your variable.
For example, if string is
5551212 and search_pattern is 51, the value 3 is assigned to your
variable.
Search is a string operation. If either string or search_pattern is a number, it is treated as a string, not a
numeric value.
- TOUpper.
- Capitalizes all the letters
in string and assigns the capitalized string to your variable.
- ToLower.
- Makes sure none of the
letters in string are capitalized and assigns the lowercase string
to your variable.
Examples
count_out = count_in % 100 ;
The arithmetic operation modulus (%) is used to set the value of
the variable count_out.
num = FUNCTION TRUNCATE (acct, -1) ;
The value of acct is truncated to the tens position and assigned
to the variable num. If the value of acct is 12897, num is assigned a value of 12890.
Procedure
Use the following procedure to assign a value to a variable:
- Selecting the Assign Data statement: Click Statements —> Assignment.
The system displays the Assignment
Definition window.
- Specifying the result variable: Type the name of
the result variable next to Result, or click Result to select
the variable.
- Selecting the assignment type: Click the push button
next to Assignment Type, then click:
- Assign to specify a direct assignment to the Result variable
- Arithmetic to specify an assignment from the result of a specified
arithmetic operation to the Result variable.
- Function to specify an assignment from the result of a specified
function to the Result variable.
- Specifying an Assign assignment: To specify a direct
assignment, type the name of the variable to be assigned to Result in
the Value field, or click Value to display the Term Definition
window to select the variable.
- Specifying an Arithmetic assignment: To specify
an arithmetic assignment:
- Type the name of the left operand variable in the Left Operand field,
or click Left Operand to display the Term Definition window to select
the operand.
- Click the push button next to Operator to select the required
operator (Add, Subtract, Multiply, Divide, or Mod (modulus)).
- Type the name of the right operand variable in the Right Operand field,
or click Right Operand to select the operand.
- Specifying a Function assignment: To specify a function
assignment:
- Type the function name in the Function field, or click Function to display the Function Definition window to select the function.
In the Function Definition window, the system displays the parameters, if
any, for the selected function.
- Supplying parameters: In the Function Definition
window:
- Adding the statement to the prompt: Click OK.
The assignment statement is added to the prompt.