Pathway/iTS SCREEN COBOL Reference Manual (G06.24+, H06.03+, Pathway/iTS 1.0+)

SCREEN COBOL Source Program
Compaq NonStop™ Pathway/iTS SCREEN COBOL Reference Manual426750-001
2-15
Evaluation of Expressions
Evaluation of Expressions
Parentheses can be used to specify the order in which the operations of an arithmetic
expression are performed. Expressions within parentheses are evaluated first.
Evaluation of expressions within nested parentheses proceeds from the innermost set to
the outermost set. When parentheses are not used, or expressions in parentheses are at
the same level, the order of execution is as follows:
1. Unary plus and minus
2. Multiplication and division
3. Addition and subtraction
Parentheses are used to eliminate ambiguities in logic or to modify the normal sequence
of execution in expressions where it is necessary to have some deviation. When the
sequence of execution is not specified by parentheses, the order for consecutive
operations at the same level is from left to right. The following example illustrates the
normal evaluation order in the absence of parentheses:
a + b / c + d * f - g
is interpreted as:
(a + (b / c)) + (d * f) - g
with the sequence of operations proceeding from the innermost parentheses to the
outermost. Expressions ordinarily considered ambiguous, such as:
a / b * c, a / b / c
are permitted in SCREEN COBOL. They are interpreted as if they were written:
(a / b) * c, (a / b) / c
Data items and literals appearing in an arithmetic expression must represent either
numeric elementary data items or numeric literals.
Multiple Results
The ADD, COMPUTE, MULTIPLY, and SUBTRACT statements can have multiple
results. Such statements behave as though they had been written in the following way:
1. One statement performs all necessary arithmetic to arrive at a result, and stores that
result in a temporary storage location.
2. A sequence of statements transfers or combines the value of this temporary location
with each result. These statements are considered to be written in the same left-to-
right sequence in which the multiple results are listed.
For example, the result of the following statement:
ADD a, b, c TO c, d(c), e