$IF Statement

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


  1. constant-name-1 is defined by a level 78 item or a CONSTANT compiler flag.
  2. 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:
    1. No spaces are allowed between the NO and the directive name
    2. 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.

  3. The entire statement must appear on a single line.
  4. $IF can be nested within another $IF.

General Rules

  1. 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.
  2. Directive setting SET evaluates true if the given string matches the actual directive setting.
  3. The comparison between directive-setting and the actual directive is case-sensitive.
  4. 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.