ISO2002 EVALUATE Directive

The EVALUATE directive provides for multi-branch conditional compilation.

General Format
Format 1
Format 2
Syntax Rules
    All Formats
  1. Each pair of contiguous COBOL characters >> and the succeeding compiler-directive words and operands up to, but not including, source-text-1 and source-text-2 must be specified on a new line and be specified entirely on that line. The first text-word of source-text-1 and the first text-word of source-text-2 must each begin on a new line.
  2. Source-text-1 and source-text-2 can be any kind of source text, including compiler directives. Source-text-1 and source-text-2 can span multiple lines.
  3. Format 1
  4. All operands of one EVALUATE directive must be of the same category. For this rule, an arithmetic expression is of category numeric.
  5. If the THROUGH phrase is specified, all selection subjects and selection objects must be of category numeric.
  6. The words THROUGH and THRU are equivalent.
General Rules
    All Formats
  1. The EVALUATE directive is processed during the processing of COPY and REPLACE statements.
  2. Format 1
  3. Literal-1 or arithmetic-expression-1, referred to as the selection subject, is compared against the values specified in each WHEN phrase in turn as follows:
    1. If the THROUGH phrase is not specified, a TRUE result is returned if the selection subject is equal to literal-2 or arithmetic-expression-2.
    2. If the THROUGH phrase is specified, a TRUE result is returned if the selection subject lies in the inclusive range determined by literal-2 or arithmetic-expression-2 and literal-3 or arithmetic-expression-3.

    As soon as a WHEN phrase is found that yields a TRUE result, the associated source-text-1 is compiled and all remaining lines up to and including the >>END-EVALUATE line are ignored. If no WHEN phrase yields a TRUE result, the source-text-2 associated with the >>WHEN OTHER phrase, if specified, is compiled.

  4. Format 2
  5. For each WHEN phrase in turn, the constant-conditional-expression is evaluated.

    As soon as a WHEN phrase is found that yields a TRUE result, the associated source-text-1 is compiled and all remaining lines up to and including the >>END-EVALUATE line are ignored. If no WHEN phrase yields a TRUE result, the source-text-2 associated with the >>WHEN OTHER, if specified, is compiled.