Using the EVALUATE statement
You can use the EVALUATE
statement instead of a series of nested IF
statements to
test several conditions and specify a different action for each. Thus
you can use the EVALUATE
statement to implement a case
structure or decision table.
About this task
You can also use the EVALUATE
statement
to cause multiple conditions to lead to the same processing, as shown in these examples:
In an EVALUATE
statement,
the operands before the WHEN
phrase are referred
to as selection subjects, and the operands in the WHEN
phrase
are called the selection objects. Selection subjects
can be identifiers, literals, conditional expressions, or the word TRUE
or FALSE
.
Selection objects can be identifiers, literals, conditional or arithmetic
expressions, or the word TRUE
, FALSE
,
or ANY
.
You can separate multiple
selection subjects with the ALSO
phrase. You can
separate multiple selection objects with the ALSO
phrase.
The number of selection objects within each set of selection objects
must be equal to the number of selection subjects, as shown in this
example:
Example: EVALUATE testing several conditions
Identifiers, literals, or arithmetic expressions that appear
within a selection object must be valid operands for comparison to
the corresponding operand in the set of selection subjects. Conditions
or the word TRUE
or FALSE
that appear
in a selection object must correspond to a conditional expression
or the word TRUE
or FALSE
in the
set of selection subjects. (You can use the word ANY
as
a selection object to correspond to any type of selection subject.)
The
execution of the EVALUATE
statement ends when one
of the following conditions occurs:
- The statements associated
with the selected
WHEN
phrase are performed. - The statements associated with the
WHEN OTHER
phrase are performed. - No
WHEN
conditions are satisfied.
WHEN
phrases
are tested in the order that they appear in the source program. Therefore,
you should order these phrases for the best performance. First code
the WHEN
phrase that contains selection objects that
are most likely to be satisfied, then the next most likely, and so
on. An exception is the WHEN OTHER
phrase, which
must come last.
EVALUATE statement (COBOL for Linux® on x86 Language Reference)
General relation conditions (COBOL for Linux on x86 Language Reference)