|
HP COBOL Reference Manual
DIVIDE ITEMA INTO ITEMB ITEMD = 2
GIVING ITEMD REMAINDER ITEMC. ITEMC = 6.00
|
REMAINDER phrase with rounding:
DIVIDE ITEMA INTO ITEMB ITEMD = 3
GIVING ITEMD ROUNDED REMAINDER ITEMC. ITEMC = 6.00
|
Effects of decimal alignment on quotient and remainder:
DIVIDE ITEMA INTO ITEMB ITEME = 2.66
GIVING ITEME REMAINDER ITEMC. ITEMC = .06
|
Effects of decimal alignment on remainder and quotient with
rounding:
DIVIDE ITEMA INTO ITEMB ITEME = 2.67
GIVING ITEME ROUNDED REMAINDER ITEMC. ITEMC = .06
|
The ON SIZE ERROR phrase: (IF ON SIZE ERROR occurs on an occurrence
of rsult, the contents of that occurrence of rsult
are unchanged.)
DIVIDE ITEME INTO ITEMF
GIVING ITEMG ITEMD ITEMD = 15
ON SIZE ERROR ITEMG = 9
MOVE 0 TO ITEMH. ITEMH = 0
|
The ON SIZE ERROR phrase: (IF ON SIZE ERROR occurs on
remaind, the contents of remaind are unchanged.)
DIVIDE ITEMD INTO ITEMF
GIVING ITEMI REMAINDER ITEMG ITEMI = 3
ON SIZE ERROR ITEMG = 9
MOVE 0 TO ITEMH. ITEMH = 0
|
The NOT ON SIZE ERROR phrase:
DIVIDE ITEMD INTO ITEMF ITEMI = 3
GIVING ITEMI REMAINDER ITEMC ITEMC = 11.00
ON SIZE ERROR
MOVE 0 TO ITEMH
NOT ON SIZE ERROR
MOVE 1 TO ITEMH. ITEMH = 1
|
6.8.12 EVALUATE
Function
The EVALUATE statement selects a program action based on the evaluation
of one or more conditions.
subj-item
is an identifier, an arithmetic or conditional expression, or a literal
other than the figurative constant ZERO.
cond
is a conditional expression.
obj-item
is a literal, an identifier, or an arithmetic expression.
stment1
is an imperative statement.
stment2
is an imperative statement.
Syntax Rules
- Before the first WHEN phrase: (a) subj-item and the words
TRUE and FALSE are called subjects, and (b) all subjects comprise the
subject set.
- In a WHEN phrase: (a) ANY, TRUE, FALSE, and the operands are called
objects, and (b) all objects in a single WHEN phrase comprise an object
set.
- The number of objects in the object set must equal the number of
subjects in the subject set.
- The words THROUGH and THRU are equivalent.
- Two obj-items connected by a THROUGH phrase:
- Must be of the same class
- Combine to form one object
- Each object in an object set must correspond to the subject by
appearing in the same ordinal position as in the subject set. For each
pair:
- The obj-item must be a valid operand for comparison to the
subject.
- TRUE, FALSE, or cond as an object must correspond only to TRUE,
FALSE, or a conditional expression as the subject.
- ANY can correspond to any type of subject.
- Conditional expressions can be simple or complex conditions.
General Rules
Evaluation Procedure
- The EVALUATE statement operates as if each subject and object were
evaluated and assigned one of the following:
- A numeric or nonnumeric value
- A range of numeric or nonnumeric values
- A truth value
The statement assigns values according to the following rules:
|
Condition |
Value Assigned |
a.
|
An identifier for a subject, or for an object without the NOT or
THROUGH phrases
|
Value and class of the identifier's data item.
|
b.
|
A literal for a subject, or for an object without the NOT or THROUGH
phrases
|
Value and class of the literal.
|
c.
|
The figurative constant ZERO for an object without the NOT or THROUGH
phrases
|
Value and class of the corresponding subject.
|
d.
|
An arithmetic expression for a subject, or for an object without the
NOT or THROUGH phrases
|
Numeric value, according to the rules for evaluating arithmetic
expressions.
|
e.
|
A conditional expression for a subject or a conditional expression for
an object
|
Truth value, according to the rules for evaluating conditional
expressions.
|
f.
|
TRUE or FALSE as a subject or object
|
Truth value: true for the word TRUE and false for the word FALSE.
|
g.
|
ANY for an object
|
No further evaluation.
|
h.
|
THROUGH phrase for an object without the NOT phrase
|
The range of values is all values that, when compared to the subject,
are greater than or equal to the first obj-item and less than or equal
to the second obj-item. If the first obj-item is greater than the
second obj-item, there are no values in the range.
|
i.
|
Object with the NOT phrase
|
All values not equal to the value (or range of values) that would be
assigned without the NOT phrase.
|
Comparison Procedure
- After values have been assigned to each subject and object,
comparison begins. It proceeds as if the values were compared to
determine if any WHEN phrase satisfies the subject set.
- EVALUATE compares each object in the object set of the first WHEN
phrase to the subject in the same ordinal position in the subject set.
The comparison is satisfied if one of the following conditions is true:
- The items being compared are assigned numeric or nonnumeric values
or a range of numeric or nonnumeric values; and the value assigned to
the subject equals the value, or one of the range of values, assigned
to the object, according to the rules for comparison.
- The items being compared are assigned identical truth values.
- The word ANY represents the object.
- If the comparison is satisfied for every object in an object set,
the WHEN phrase containing that object set is selected.
- If the comparison is not satisfied for every object in an object
set, the object set does not satisfy the subject set.
- The comparison procedure is repeated for each object set, in order
of appearance, until one of these conditions occur:
- A WHEN phrase is selected by satisfying the subject set.
- A WHEN OTHER phrase is selected.
- There are no more object sets.
- The END-EVALUATE statement is reached.
- A separator period is reached.
Execution Procedure
- If a WHEN phrase is selected, execution continues with
stment1.
- If no WHEN phrase is selected, and a WHEN OTHER phrase is present,
execution continues with stment2.
- EVALUATE statement execution ends when one of the following
conditions occurs:
- Execution reaches the end of the selected WHEN phrase.
- Execution reaches the end of the WHEN OTHER phrase.
- No WHEN phrase is selected and there is no WHEN OTHER phrase.
- Execution reaches END-EVALUATE.
- Execution reaches a separator period.
Additional References
Examples
In these examples, the results are shown as either data item values or
procedure branches. However, stment can be any
imperative statement, including multiple statements.
- One condition.
EVALUATE ITEMA
WHEN "A01" MOVE 1 TO ITEMB
WHEN "A02" THRU "C16" MOVE 2 TO ITEMB
WHEN "C20" THRU "L86" MOVE 3 TO ITEMB
WHEN "R20" ADD 1 TO R-TOT
GO TO PROC-A
WHEN OTHER MOVE 0 TO ITEMB
END-EVALUATE.
|
Samples:
ITEMA |
Result |
"A15"
|
ITEMB = 2
|
"P80"
|
ITEMB = 0
|
"F01"
|
ITEMB = 3
|
"M19"
|
ITEMB = 0
|
"A01"
|
ITEMB = 1
|
"R20"
|
PROC-A
|
- Multiple conditions. This example shows how EVALUATE can represent
a decision table.
|