Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Compiler directives

General

COBOL programmers can use compiler directive to specify compilation options and control the manipulation of the source text. In particular, compiler directives can be used to control conditional compilation.

Syntax rules for all compiler directives

  1. A compiler directive can be preceded by any number of space characters.

  2. A compiler directive must be specified in the program-text area (relative to the reference format) and may be followed only by space characters.

  3. A compiler directive begins with the character string “>> “, followed by an optional space and the actual directive.

  4. A compiler directive must be specified alone on a single line, except for the EVALUATE ( "EVALUATE directive") and IF ( "IF directive") directives.

  5. A compiler directive may also be specified in library text (see COPY, section "Statements for source text manipulation").

  6. EVALUATE and IF directives in COPY elements within the copied text must be terminated with the associated >>END-EVALUATE or >>END-IFCOPY elements.

  7. The maximum nesting depth for directives is 256.

  8. A compiler directive may be specified anywhere except in the following cases:

General rules for all compiler directives

  1. A compiler directive is not affected by a "replacing action" of a COPY or REPLACE statement.

  2. Compiler directives apply either in the source text manipulation phase, in the listing generation phase or in the compilation phase (see "Controlling the compiler").
    During the compilation phase the compiler directives are processed in the order in which they occur in the compilation group.

  3. Compiler directives apply for all subsequent source texts and library texts and are independent of the program flow.

  4. Compiler directives are regarded as coming before a compilation unit if this is not specified between the outermost IDENTIFICATION DIVISION (or, if this is missing, the ID paragraph) and the associated END entry.

  5. If a compilation unit contains more than 65535 lines (this includes comment and empty lines and compiler directives which are specified before the IDENTIFICATION DIVISION and are not assigned to this compilation unit), directives which are normally effective during the compilation phase are ignored if they are specified inside this compilation unit.

     

Arithmetical expression

An arithmetical expression may consist of integers, constant names and the characters “(“, “)”, “+”, “-”, “*”, “/”. The range of values must be representable as a 32-bit number for all intermediate results. Decimal places may be truncated as necessary.

The following must apply for the range of values of the literal represented by the arithmetic expression as well as for the range of values of all the intermediate results derived during the calculation of the arithmetic expression:

-231 < range of values < 231-1

Boolean expression

The following constitute boolean expressions:

  • A relation condition in which both operands are literals or arithmetic expressions which are formed from literals. Names of compilation variables from DEFINE directives can also be used in place of literals.

  • DEFINED condition

  • Expressions consisting of the logical operators AND, OR, NOT and any bracketed boolean expressions.

    Expressions in directives which contain logical operands (AND or OR) need to be fully bracketed in order to ensure that the logical operators are processed in the correct order. Only when partial logical expressions are used can additional bracketing be omitted and the usual rules of priority be applied.

Conditional compilation

Some compiler directives can be used to include or omit selected lines of source code in the compilation. This is called conditional compilation.
The DEFINE, EVALUATE and IF directives are intended for this purpose.

DEFINED condition

Format


compilation-variable-name-1 IS [ NOT ] DEFINED


Syntax rule

  1. compilation-variable-name-1 must not be a word reserved for the compiler directives (see “Reserved words for compiler directives” in section "COBOL words").

General rules

  1. If IS DEFINED is specified and compilation-variable-name-1 is defined, the condition will evaluate to “true”.
    if NOT DEFINED is specified and compilation-variable-name-1 is not defined, the condition will still evaluate to “true”.

    compilation-variable-name-1 is defined if the following conditions are satisfied:

    • compilation-variable-name-1 is specified in a DEFINE directive (see section "DEFINE directive") without an OFF clause.

    • If the PARAMETER clause is specified in the DEFINE directive and the value was provided by the operating system (see the "COBOL2000 User Guide" [1]).