WHEN-IN (When the SELECT Operand is IN the WHEN-IN Operand)
WHEN-IN (When the SELECT Operand is IN the WHEN-IN Operand)
| Free-Form Syntax | WHEN-IN expression |
| Code | Factor 1 | Extended Factor 2 | ||||
|---|---|---|---|---|---|---|
| WHEN-IN | expression |
The WHEN-IN operation code is similar to the WHEN operation code in that it controls the processing of lines in a SELECT operation. It differs in that the operations following the WHEN-IN statement are performed when the expression specified by the operand of the SELECT statement is in the operand specified by the operand of the WHEN-IN statement, according to the rules of the IN operator.
The operand of the WHEN-IN statement can be:
See WHEN-IS for another operation code that can be used when the SELECT statement has an operand.
For more information, see Compare Operations or Structured Programming Operations.
Examples of the WHEN-IN operation
-
In the following example:
- Variable
salaryis specified as the first operand of the SELECT statement. - If the value of
salaryis in %RANGE(0:100), the statements following the first WHEN-IN statement are executed, and then control passes to the ENDSL statement. - If the first WHEN-IN statement was
not true, and the value of
salaryis between 100 and 200, the statements following the second WHEN-IN statement are executed, and then control passes to the ENDSL statement. - If none of the WHEN-IN statemnents are satisfied, then control passes to statements following the OTHER statement.
DCL-S salary PACKED(10 : 2); SELECT salary; // 1 WHEN-IN %RANGE(1 : 100); // 2 ... WHEN-IN %RANGE(100 : 200); // 3 ... OTHER; // 4 ... ENDSL; - Variable
-
In the following example:
- Variable
itemTypeis specified as the first operand of the SELECT statement. - If the value of
itemTypeis in the list of items specified by the %LIST built-in function, the statements following the first WHEN-IN statement are executed, and then control passes to the ENDSL statement. - If the previous WHEN-IN statement was not satisfied,
and the value of
itemTypeis equal to the value returned by the todaysSpecial procedure, the statements following the WHEN-IS statement are executed, and then control passes to the ENDSL statement. - If the previous WHEN-IN and WHEN-IS statements were not satisfied,
and the value of
itemTypeis equal to one of the elements of theshoeTypesarray, the statements following the next WHEN-IN statement are executed, and then control passes to the ENDSL statement. - If the previous WHEN-IN and WHEN-IS statements were not satisfied,
and the value of
itemTypeis equal to one of the elements in the subarray specified by the %SUBARR built-in function, the statements following the second WHEN-IN statement are executed, and then control passes to the ENDSL statement. - If none of the previous WHEN-IN and WHEN-IS statements were satisfied, the statements following the OTHER statement are executed, and then control passes to the ENDSL statement.
DCL-S itemType CHAR(10); DCL-S shoeTypes CHAR(30) DIM(5); DCL-S clothingTypes VARCHAR(20) DIM(10); DCL-S numClothingTypes INT(10); SELECT itemType; // 1 WHEN-IN %LIST('Toys' : 'Games'); // 2 ... WHEN-IS todaysSpecial(); // 3 ... WHEN-IN shoeTypes; // 4 ... WHEN-IN %SUBARR(clothingTypes : 1 : numClothingTypes); // 5 ... OTHER; // 6 ... ENDSL; - Variable
For more examples of the WHEN-IN operation, see SELECT (Begin a Select Group) and WHEN-IS (When the SELECT Operand is Equal to the WHEN-IS Operand).