SELECT


PLBCMP Only

 

The SELECT instruction provides a multi-way branch that allows a series of conditional statements to evaluate multiple conditions. The instruction uses the following format:

 

 

[label]

SELECT

USING {select1}[,{select2}[...{select10}]]

 

 

WHEN

{when1}[,{when2}[...{when10}]]

 

 

DEFAULT

 

 

 

ENDSELECT

 

 

Where:

label

Optional. A Program Execution Label.

select1

Required. A Character Variable, Numeric Variable, an Expression, or a decimal constant value evaluated.

select2

Optional. An additional Character String Variable, Numeric Variable, an Expression, or a decimal constant value evaluated.

select10

Optional. An additional Character String Variable, Numeric Variable, an Expression, or a decimal constant value evaluated.

when1

Required. A Character String Variable, Numeric Variable, an Expression, or a decimal constant value matched or compared with the first operand in the SELECT statement.

when2

Optional. An additional Character String Variable, Numeric Variable, an Expression, or a decimal constant value matched or compared with the corresponding operand in the SELECT statement.

when10

Optional. An additional Character String Variable, Numeric Variable, an Expression or a decimal constant value matched or compared with the corresponding operand in the SELECT statement.

Flags Affected: NONE

Note the following:

  1. The SELECT statement defines the beginning of the construct and requires one or more SELECT operands specified in the statement.

  2. No executable statements are allowed between the SELECT and the first WHEN statement.

  3. The ENDSELECT statement defines the end of the construct.

  4. At least one WHEN statement must be specified between the SELECT and the ENDSELECT statements. Any number of additional WHEN statements may be used.

  5. An optional DEFAULT statement may be specified after the last WHEN statement but before the ENDSELECT. Only one DEFAULT statement is allowed.

  6. The SELECT may have up to ten (10) operands specified with a comma delimiter between each.

  7. Each operand specified for the SELECT statement defines a selection criteria used when evaluating each WHEN statement.

  8. Each WHEN statement operand is compared or matched to the corresponding SELECT operand defined.

  9. The data type for a WHEN operand must be the same as the corresponding operand for the SELECT statement.

  10. If all of the WHEN operands match or compare to all of the SELECT operands, the WHEN statement is determined to satisfy the selection criteria and the statements following the WHEN statement are executed. The statements for only one WHEN statement are executed when the selection criteria is determined to satisfy all operands.

  11. Each WHEN statement operand may be specified as more than one selection criteria.

  12. If a WHEN statement operand has more than one selection criteria and defines a range, the selection criteria items are separated by the keyword 'THRU'. This allows the matching condition to occur when the SELECT operand is determined within the range specified inclusive.

  13. If a WHEN statement operand has more than one selection criteria item, the keyword 'OR' must separate the selection criteria items. In this case, either selection criteria item matching the corresponding SELECT operand may satisfy a matching condition.

  14. If a WHEN operand is not specified, the corresponding SELECT operand is considered to match the NULL WHEN operand.

  15. Nesting of the SELECT/WHEN/DEFAULT/ENDSELECT construct is allowed up to 32 levels.

 

 

See Also: Example Code, Program Control Instructions

 



PL/B Language Reference ROUTINE SETFLAG