Conditional compilation

Conditional compilation provides a way of including or omitting selected lines of source code depending on the values of literals specified by the DEFINE directive. In this way, you can create multiple variants of the same program without the need to maintain separate source streams.

The compiler directives that are used for conditional compilation are the DEFINE directive, the EVALUATE directive, and the IF directive. The DEFINE directive is used to define compilation variables that are referenced in the EVALUATE and IF directives to select lines of source code that are to be included or omitted in a compilation group.

Conditional compilation directives are processed according to the following rules:
  • Within a source file, if a conditional compilation directive appears before a COPY or REPLACE statement, it is processed before the COPY or REPLACE statement is processed. This means that conditional compilation directives may be used to exclude COPY and REPLACE statements from a program.
  • Conditional compilation directives are not affected by substitutions made as the result of REPLACE statements or the REPLACING phrase of COPY statements.
  • Conditional compilation directives may appear in copybooks.
Notes:
  • Conditional compilation directives can be included in a file that contains the BASIS statement, but in that file, conditional compilation directives do not control the inclusion or exclusion of source from that file. Instead, the conditional compilation directives will be processed like any other source lines in the BASIS file that are not INSERT or DELETE statements, and those directives will be passed through to the source that is being assembled to be processed later during the library phase.
  • Start of changeConditional compilation directives along with their included and excluded source text can be viewed in the listing. Excluded source text can be omitted from the listing by using the CONDCOMP(SKIPSRC) option.End of change
Related references  
DEFINE  
EVALUATE  
IF  
CONDCOMP (Enterprise COBOL Programming Guide)
Example: conditional compilation output (Enterprise COBOL Programming Guide)