The $IF Statement provides the ability to conditionally include or exclude text based on the state of certain variables. There
are three formats:
Format 1
$IF constant-name-1 [NOT] {< > =} literal-1
Format 2
$IF constant-name-2 [NOT] DEFINED
Format 3
$IF directive-setting SET
Syntax
- constant-name-1 is defined by a level 78 item or a CONSTANT compiler flag.
- directive-setting is specified in the same format as it is given in the
$SET statement and may be preceded by NO. However, the format used in the
$IF statement differs from the format used in the
$SET statement as follows:
- No spaces are allowed between the NO and the directive name
- Case must be preserved in the directive
directive-setting may also be specified at compile time by using the
-/ (forward slash) compiler option. See Conditional Compilation Options for details on this and other conditional compiler options.
- The entire statement must appear on a single line.
- $IF can be nested within another
$IF.
General Rules
- constant-name-2 is DEFINED if it is the name of a level 78 item or a CONSTANT compiler flag. Otherwise it is NOT DEFINED.
- Directive setting SET evaluates
true if the given string matches the actual directive setting.
- The comparison between
directive-setting and the actual directive is case-sensitive.
- If the condition evaluates "true", the source lines following the $IF statement are processed. If the condition evaluates
"false", COBOL source lines are ignored until the next conditional compilation line is encountered.