EVALUATE Statement COBOL

The EVALUATE statement describes a multi-branch, multi join structure. It can cause multiple conditions to be evaluated. The subsequent action of the object program depends on the results of these evaluations.

EVALUATE Statement

The operands or the words TRUE and FALSE which appear before the first WHEN phrase of the EVALUATE statement are referred to individually as selection subjects and collectively, for all those specified, as the set of selection subjects.

The operands or the words TRUE, FALSE and ANY which appear in a WHEN phrase of an EVALUATE statement are referred to individually as selection objects and collectively, for all those specified in a single WHEN phrase, as the set of selection objects.

The words THROUGH and THRU are synonymous.

Two operands connected by a THROUGH phrase must be of the same class. The two operands thus connected constitute a single selection object.

The number of selection objects within each set of selection objects must be equal to the number of selection subjects.

Each selection object within a set of selection objects must correspond to the selection subject having the same ordinal position within the set of selection subjects according to the following rules:

  1. Identifiers, literals or arithmetic expressions appearing within a selection object must be valid operands for comparison to the corresponding operand in the set of selection subjects.
  2. condition or the word TRUE or FALSE appearing as a selection object must correspond to a conditional expression or the word TRUE or FALSE in the set of selection subjects.
  3. The word ANY may correspond to a selection subject of any type.

General Rules

The general rules that apply to the EVALUATE statement are as follows:

  1. The execution of the EVALUATE statement operates as if each selection subject and selection object were evaluated and assigned a numeric or nonnumeric value, a range of numeric or nonnumeric values, or a truth value. These values are determined as follows:
    • Any selection subject specified by identifier-1, identifier-2, and any selection object specified by identifier-3, identifier-5 without either the NOT or the THROUGH phrase, are assigned the value and class of the data item referenced by the identifier.
    • Any selection subject specified by literal-1, literal-2, and any selection object specified by literal-3, literal-5 without either the NOT or the THROUGH phrase, are assigned the value and class of the specified literal.If literal-3 is the figurative constant ZERO, it is assigned the class of the corresponding selection subject.
    • Any selection subject in which arith-expr-1, arith-expr-2 is specified as an arithmetic expression and any selection object, without either the NOT or the THROUGH phrase, in which arith-expr-3, arith-expr-5 is specified, are assigned a numeric value according to the rules for evaluating an arithmetic expression.
    • Any selection subject in which condition-1, condition-2 is specified as a conditional expression and any selection object in which condition-3, condition-4 is specified, are assigned a truth value according to the rules for evaluating conditional expressions.
    • Any selection subject or any selection object specified by the word TRUE or FALSE is assigned a truth value.The truth value “true” is assigned to those items specified with the word TRUE, and the truth value “false” is assigned to those items specified with the word FALSE.
    • Any selection object specified by the word ANY is not further evaluated.
    • If the THROUGH phrase is specified for a selection object, without the NOT phrase, the range of values includes all permissible values of the selection subject that are greater than or equal to the first operand and less than or equal to the second operand according to the rules for comparison.
    • If the NOT phrase is specified for a selection object, the values assigned to that item are all permissible values of the selection subject not equal to the value, or not included in the range of values, that would have been assigned to the item had the NOT phrase not been specified.
  2. The execution of the EVALUATE statement then proceeds as if the values assigned to the selection subjects and selection objects were compared to determine if any WHEN phrase satisfies the set of selection subjects.This comparison proceeds as follows:
    • Each selection object within the set of selection objects for the first WHEN phrase is compared to the selection subject having the same ordinal position within the set of selection subjects.
    • One of the following conditions must be satisfied if the comparison is to be satisfied:
      1. If the items being compared are assigned numeric or nonnumeric values, or a range of numeric or nonnumeric values, the comparison is satisfied if the value, or one of the range of values, assigned to the selection object is equal to the value assigned to the selection subject according to the rules for comparison.
      2. If the items being compared are assigned truth values, the comparison is satisfied if the items are assigned the identical truth value.
      3. If the selection object being compared is specified by the word ANY, the comparison is always satisfied regardless of the value of the selection subject.
    • If the above comparison is satisfied for every selection object within the set of selection objects being compared, the WHEN phrase containing that set of selection objects is selected as the one satisfying the set of selection subjects.
    • If the above comparison is not satisfied for one or more selection objects within the set of selection objects being compared, that set of selection objects does not satisfy the set of selection subjects.
    • This procedure is repeated for subsequent sets of selection objects, in the order of their appearance in the source program, until either a WHEN phrase satisfying the set of selection subjects is selected or until all sets of selection objects are exhausted.
  3. After the comparison operation is completed, execution of the EVALUATE statement proceeds as follows:
    • If a WHEN phrase is selected, execution continues with the first imperative-statement-1 following the selected WHEN phrase.
    • If no WHEN phrase is selected and a WHEN OTHER phrase is specified, execution continues with imperative-statement-2.
    • The scope of execution of the EVALUATE statement is terminated when execution reaches the end of imperative-statement-1 of the selected WHEN phrase or the end of imperative-statement-2, or when no WHEN phrase is selected and no WHEN OTHER phrase is specified.

EVALUATE Statement Examples


Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics