Conditional Compilation [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
Conditional Compilation
Usually, when you compile a source file, you want the entire program
compiled. However, there may be occasions when you want only part of the
program compiled. Conditional compilation, that is, compilation of
source code contingent upon whether a switch is on or off, is
accomplished by using the $SET and $IF preprocessor commands.
$SET Command
The $SET preprocessor command may be used to turn ten compilation
switches on or off. The ten software switches are of the form, Xn, where
n is an integer in the range 0 through 9.
The $SET command has the following format:
$SET [Xn={ON } [, Xr={ON }]...]
[ {OFF} [ {OFF}] ]
where Xn and Xr are compilation switches as described above.
Initially, all compilation switches are set to OFF.
A $SET command may appear anywhere in the source text. If used without
parameters, that is, in the form $SET, it sets all switches to OFF.
$IF Command
The $IF command interrogates any of the ten compilation switches. If the
condition specified in the $IF command is true, source records are sent
to the compiler, beginning with the first one following the $IF command,
and continuing until another $IF command is encountered which is false.
If the condition specified by the $IF command is false, no source records
are sent to the compiler until a $IF command which is true is
encountered. Note also, that during this processing any $SET and
$CONTROL commands encountered are ignored by the compiler.
The $IF command has the following format:
$IF [Xn= {ON }]
[ {OFF}]
where Xn is a compilation switch as described under the $SET command in
the preceding paragraphs.
The $IF command may appear anywhere in the source text.
The appearance of a $IF command always terminates the influence of any
preceding $IF command.
When a $IF command is entered without a parameter, it has the same effect
as a $IF command whose condition is true. That is, the text following
the command is compiled, and any previous $IF command is canceled.
Note that the merging of a text and master source file, and copying of
this merged file to a newfile is unaffected by $IF commands. Also, the
$EDIT, $PAGE, and $TITLE commands are executed even when they appear in a
portion of source code that is not to be sent to the compiler. However,
all other preprocessor commands are ignored in such a portion of source
code, that is, $SET, $CONTROL, etc.
If you do not want to list source records that are not compiled, you must
use the CONTROL preprocessor command, specifying the NOMIXED parameter.
Example.
$SET X1=ON, X3=ON
:
$IF X1=ON
$COMMENT SINCE X1 IS ON, CONTINUE SENDING RECORDS TO THE &
$ COMPILER.
:
$IF X3=OFF
$COMMENT THIS $IF COMMAND CANCELS THE PRECEDING ONE. SINCE &
$ X3 IS SET TO "ON", DO NOT SENT THE FOLLOWING RECORDS &
$ TO THE COMPILER.
$SET X2=ON
$CONTROL NOLIST.
$COMMENT NOTE THAT THE $SET AND $CONTROL COMMANDS ARE &
$ IGNORED, SINCE THE PREVIOUS $IF WAS FALSE.
$IF
$COMMENT PREVIOUS $IF CONDITION IS TERMINATED, AND COMPILATION &
$ RESUMES.
MPE/iX 5.0 Documentation