Command reference / CL

WHEN

When

Evaluates a logical expression and conditionally processes CL or ILE CL commands. If the expression is true, the command (or Do group) on THEN is processed, and later WHEN and OTHERWISE commands in the SELECT group are skipped; control then goes to the command after the ENDSELECT. If it is false, control passes to the next WHEN or OTHERWISE. If THEN is an IF, DO, DOWHILE, DOUNTIL or DOFOR, the whole group is bypassed when the expression is false.

Allowed environments: *BPGM, *IPGM. Use within a CL program. Positional parameters: 2.

Restrictions

Parameters

COND Condition

Specifies the logical expression that is evaluated to determine a condition in the program and what is done next. Variables, constants, and the %SUBSTRING, %SWITCH and %BINARY built-in functions can be used within the expression.

Type
*CHAR
Required
Yes
Length
50
Case
Uppercase
*NULL
Tests a CL pointer variable for a null value when compiled with CRTCLMOD or CRTBNDCL. With CRTCLPGM, compare to a pointer declared with ADDRESS(*NULL) instead.

THEN Command

Specifies the command, or group of commands in a Do group or If command, that is processed if the logical expression is true. A null THEN passes control to the command after the ENDSELECT.

Type
*CMDSTR
Required
No
Case
Uppercase

Examples

WHEN COND(&NAME *EQ *CMD) THEN(DO) ... ENDDO

The WHEN command runs its THEN group if &NAME equals *CMD; WHEN commands are evaluated in order, and if no condition is met, processing continues after ENDSELECT.

IBM command documentation

Generated from os/cl/catalog/WHEN.json and os/cl/help/WHEN.json.