CL Command Reference - OTHERWISE

CL Command List > OTHERWISE Reference

Description:

Specifies the command or group of commands (in an If or Do group) that are processed if none of the conditions on any of the When commands within a Select command group were evaluated to be true. After the command or Do group is processed, control is passed to the next command after the End Select command associated with this Otherwise command. If the command specified in this parameter is a DO, DOWHILE, DOUNTIL, or DOFOR command, all commands within the Do group are considered to be the command specified by the parameter.

Restrictions:

. This command is valid only within a CL procedure.

. This command is valid only within a SELECT-ENDSELECT command group.

. Only one OTHERWISE may be specified in a SELECT-ENDSELECT command group.

. All WHEN commands in a SELECT-ENDSELECT command group must appear before the OTHERWISE command.


Examples:

DCL VAR(&NAME) TYPE(*CHAR) LEN(10)
:
SELECT
WHEN COND(&NAME *EQ *CMD) THEN(DO)
: (group of CL commands)
ENDDO
WHEN COND(&NAME *EQ *PGM) THEN(DO)
: (group of CL commands)
ENDDO
OTHERWISE CMD(CHGVAR &NAME *PGM)
ENDSELECT

The OTHERWISE specifies the command to run if none of conditions on any of the WHEN commands in a SELECT command group command group were matched. In this example the CHGVAR will be run when the value of &NAME is not *CMD and not *PGM.