Command reference / CL
IF
If
Evaluates a logical expression and conditionally processes CL program or ILE CL procedure commands. If the expression is true, the command (or Do group) in the THEN parameter is processed and the associated ELSE command is not. If false, the THEN command is not processed and control passes to the next command; if that command is ELSE, its command or Do group is processed. A bypassed Do group passes control to the command after its ENDDO. A GOTO command transfers control to the labeled command.
Allowed environments: *BPGM, *IPGM.
Use within a CL program.
Positional parameters: 2.
Restrictions
- The IF command is valid only in a CL program or ILE CL procedure.
- Up to ten levels of nested IF and ELSE commands are allowed.
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 in the expression. This is a required parameter.
THEN
Command
Specifies the command or group of commands (in a Do group) that is processed if the expression is true. Any CL command can be specified except ELSE, PGM, ENDPGM, ENDDO, MONMSG, DCL, DCLF, WHEN, OTHERWISE, and ENDSELECT. Another IF can be nested, up to the ten-level limit.
Examples
IF COND(&A *EQ &B) THEN(GOTO X)
If &A equals &B, control passes to the CL command that has a label named X.
IF COND(&TESTSW) THEN(CHGVAR VAR(&A) VALUE(23))
If &TESTSW has a logical value of 1 (true), CHGVAR sets &A to 23. If it is 0, the CHGVAR command is not processed.
Generated from os/cl/catalog/IF.json and os/cl/help/IF.json.