skip to main content

Compiler and Runtime : Compiler : Compiler Directives : IF Directive

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
  [ >> ELSE Statement-2 ]
>> END-IF
Syntax:
1.
ConstantName is a constant defined in the configuration file as iscobol.compiler.const.ConstantName or using the DEFINE Directive compiler directive.
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
  [ $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"

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left