Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Language Reference Manual

SELECT statement

Examples

A select-group provides a multiple path conditional branch. A select-group contains a SELECT statement, optionally one or more WHEN statements, optionally an OTHERWISE statement, and an END statement.

Note:
Condition prefixes are invalid on OTHERWISE statements.
Read syntax diagramSkip visual syntax diagram                          .---------------------------.
                          V                           |
>>-SELECT--+--------+--;----+-----------------------+-+--------->
           '-(exp1)-'       |       .-,----.        |
                            |       V      |        |
                            '-WHEN(---exp2-+-)unit;-'
 
>--+--------------------+--------------------------------------><
   '-OTHERWISE--unit--;-'
 

Abbreviation: OTHER for OTHERWISE

SELECT (exp1)
The SELECT statement and its corresponding END statement, delimit a group of statements collectively called a select-group. The expression in the SELECT statement is evaluated and its value is saved.
WHEN (exp2, exp2, ...) unit
Specifies one or more expressions that are evaluated and compared with the saved value from the SELECT statement.

If an expression is found that is equal to the saved value, the evaluation of expressions in WHEN statements is terminated, and the unit of the associated WHEN statement is executed. If no such expression is found, the unit of the OTHERWISE statement is executed.

The WHEN statement must not have a label.

OTHERWISE unit
Specifies the unit to be executed when every test of the preceding WHEN statements fails.

If the OTHERWISE statement is omitted and execution of the select-group does not result in the selection of a unit, the ERROR condition is raised.

The OTHERWISE statement must not have a label or condition prefix.

unit
Each unit is either a valid single statement, a group, or a begin-block. DECLARE, DEFAULT, END, ENTRY FORMAT, PROCEDURE, and %statement statements are not valid. Each unit can contain statements that specify a transfer of control (for example, GO TO). Hence, the normal sequence of the SELECT statement can be overridden.

If exp1 is omitted, each exp2 is evaluated and converted, if necessary, to a bit string. If any bit in the resulting string is '1'B, the unit of the associated WHEN statement is executed. If all bits are 0 or the string is null, the unit of the OTHERWISE statement is executed.

After execution of a unit of a WHEN or OTHERWISE statement, control passes to the statement following the select-group, unless the normal flow of control is altered within the unit.

If exp1 is specified, each exp2 must be such that the following comparison expression has a scalar bit value:

  (exp1) = (exp2)

Both exp1 and exp2 must be scalar expressions. Hence, while arrays, structures, and unions may be used in either exp1 or exp2, the evaluated expression must be a scalar value.


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)