IN operator
IN operator
IN operator
X IN Y
The IN operator is used in a binary conditional statement to determine whether the item specified as the first operand of the IN operator is
- within a range of values using %RANGE
- equal to one of the elements in an array or sub-array
- equal to one of the items in a %LIST built-in function.
- equal to one of the constants in an enumeration. See Enumerations.
The IN operator is also used with the FOR-EACH operation code.
Examples of the IN operator
In the following example, indicator isValid is set to *ON if requestDate is in the range of startDate to endDate.
isValid = requestDate IN %RANGE(startDate : endDate);
In the following example, indicator isValid is set to *ON if stat is one of the constants in enumeration order_status.
DCL-ENUM order_status;
open 'O';
close 'C';
pending 'P';
END-ENUM;
isValid = stat IN order_status;
In the following example, the IF statement is true if item is not in the array availableItems. %SUBARR is used to limit the number of array elements checked.
IF NOT (item IN %SUBARR(availableItems : 1 : numAvailabeItems));
declineOrder (item);
ENDIF;
Note: The NOT operator is a unary operator with the highest precedence, so you must enclose the IN expression in parentheses when used with NOT.
For more examples, see %LIST (item { : item { : item … } } ), %RANGE (lower-limit : upper-limit), FOR-EACH (For Each), and Enumerations.