IF Directive
The IF directive checks the value of a constant to determine the inclusion of lines of source code.
>> IF ConstantName IS [ NOT ] DEFINED Statement-1 {[ NOT ] = ConstantValue} {[ NOT ] < ConstantValue} {[ NOT ] > ConstantValue} [ >> ELSE Statement-2 ] >> END-IF |
Syntax:
2. Statement-1 and Statement-2 are lines of COBOL code.
General rules:
1. Testing IF DEFINED, when ConstantName is defined, no matter the value, the lines in Statement-1 are included. Otherwise, the lines in Statement-2 are included.
2. Testing IF EQUAL, GREATER or LESS, when ConstantName is defined, and its value matches the IF condition, the lines in Statement-1 are included. Otherwise, the lines in Statement-2 are included.
Alternative syntax
The following equivalent syntax is supported for compatibility:
$IF ConstantName [ NOT ] DEFINED Statement-1 {[ NOT ] = ConstantValue} {[ NOT ] < ConstantValue} {[ NOT ] > ConstantValue} [ $ELSE Statement-2 ] $END |
The dollar sign must appear in the source indicator area.
Example
Show a message only if the DEBUG constant is defined:
>>IF DEBUG IS DEFINED display message "debug mode" >>END-IF ... |