Sign in

docs RPG Reference

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 SyntaxWHEN-IN expression
CodeFactor 1Extended Factor 2
WHEN-INexpression

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:

    1. Variable salary is specified as the first operand of the SELECT statement.
    2. If the value of salary is in %RANGE(0:100), the statements following the first WHEN-IN statement are executed, and then control passes to the ENDSL statement.
    3. If the first WHEN-IN statement was not true, and the value of salary is between 100 and 200, the statements following the second WHEN-IN statement are executed, and then control passes to the ENDSL statement.
    4. 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;
  • In the following example:

    1. Variable itemType is specified as the first operand of the SELECT statement.
    2. If the value of itemType is 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.
    3. If the previous WHEN-IN statement was not satisfied, and the value of itemType is 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.
    4. If the previous WHEN-IN and WHEN-IS statements were not satisfied, and the value of itemType is equal to one of the elements of the shoeTypes array, the statements following the next WHEN-IN statement are executed, and then control passes to the ENDSL statement.
    5. If the previous WHEN-IN and WHEN-IS statements were not satisfied, and the value of itemType is 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.
    6. 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;

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).