$IF Statement Example (Micro Focus COBOL Conditional Compilation)

The $IF statement can be used to "conditionally compile" portions of your source code. In the following example, if the program is compiled with the directives:

/MF /CONSTANT WHERE "PC"

then at compile time, the word "NO" will be displayed and the object code will include an EVALUATE rather than a GO TO statement. If the MF directive were not set, "Not MF dialect" would also be displayed.

$if WHERE = "PC"
     evaluate test-field
       when 5  perform test-a
     end-evaluate
$if OTHER-CONSTANT defined
$display Program compiled with other-constant set
$else
$display NO
$end
$else
     go to test-a test-b depending on test-field
$end
$if NOMF set
$display Not MF dialect
$end