Select (SELECT)

The Select (SELECT) command begins a control structure to allow conditional processing of command groups. The select group is ended with an End Select (ENDSELECT) command and must contain one or more When (WHEN) commands and optionally an otherwise (OTHERWISE) command.

When a Select command is entered, the condition specified on the first When command is evaluated. If the condition is true, the command specified on the THEN parameter is run. After the command or group of commands is processed, control will pass to the matching ENDSELECT command. Only one WHEN or the optional OTHERWISE will be processed within a SELECT group.

If the first WHEN condition is not true, subsequent WHEN commands are evaluated in the order specified. If no WHEN command condition is true, control will pass to the command specified on the OTHERWISE command, if OTHERWISE is specified.

Restrictions:

There are no parameters for this command.

Parameters

None

Examples

DCL   VAR(&INT)  TYPE(*INT)  LEN(4)
 :
SELECT
  WHEN   COND(&INT *LT 0)  THEN(DO)
    :   (group of CL commands)
  ENDDO
  WHEN   COND(&INT *EQ 0)    /* Do nothing when zero */
  WHEN   COND(&INT *GT 0)  THEN(CHGVAR &INT (&INT - 1)
ENDSELECT

The SELECT command group will evaluates the conditions of the WHEN commands in the order they are encountered. When a COND parameter results in a true value, the command specified on the THEN parameter is processed. After the command on the THEN parameter is processed, control passes to the command following the ENDSELECT command.

Error messages

None