| Introduction | MTB Statements | File System | Compiler | Applications | Reference Guide | Index |
| Language Structure | Data Division | I/O Format Division | Procedure Division | Mnemonics |
Conditional compilation is controlled by the following two compiler directives, which may appear in any section of the MTB source program:
In addition, the following directives extend the capability of the conditional compilation feature:
.IF symbolic-constant (conditional source segment) .ENDIF |
The MTB compiler will compile the conditional source segment only if the symbolic constant has been SET to a non-zero value.
Example:
In the following example, the symbolic constant named ABC is set to a non-zero value. When the compiler reaches the .IF directive, it compiles the subsequent lines up through the .ENDIF directive. Note, however, that if ABC was either not defined (not SET) or contained a value of 0, the compiler would skip the conditional source segment.
SET ABC = 1 ! set the symbolic constant to a non-zero value .IF ABC ! beginning of conditional source segment MTB code segment .ENDIF ! end of conditional source segment
.IF symbolic-constant MTB code segment 1 .ELSE MTB code segment 2 .ENDIF |
The .IF directive tests the value of the symbolic constant. If it contains a non-zero value, the first code segment is compiled (and the second segment is not). If the symbolic constant contains a value of 0 or is not SET, only the second code segment is compiled.
Example:
SET ABC=0 ! symbolic constant = 0
! therefore, compile code segment 2
.IF ABC
(segment 1)
.ELSE
(segment 2)
.ENDIF
| Directive | Description |
|---|---|
| .IFDEF symbolic-constant | Compiles the code segment only if the symbolic constant has been defined (via the SET) statement, regardless of its value. Otherwise, skips the code segment. |
| .IFNDEF symbolic-constant | Compiles the code segment only if the symbolic constant has not been defined or has been UNSET. |
Syntax: UNSET symbolic-constant
The UNSET directive clears the definition of the symbolic constant (i.e., "un-defines" it). This directive is particularly useful when working with the .IFDEF and .IFNDEF directives.
Example:
UNSET ABC ! un-define the symbolic constant named ABC