General Formats (Cont.) [ Micro Focus COBOL Language Reference ] MPE/iX 5.0 Documentation
Micro Focus COBOL Language Reference
General Formats (Cont.)
Syntax Rules (Cont.)
Syntax Rules.
1. Condition may be:
* a simple condition
* a negated simple condition
* a combined condition
* a negated combined condition; that is, the "NOT" logical
operator followed by a combined condition enclosed within
parentheses
* combinations of the above, specified according to the rules
summarized in Table 4-9.
2. Although parentheses need never be used when either "AND" or "OR"
(but not both) is used exclusively in a combined condition,
parentheses can be used to effect a final truth value when a
mixture of "AND", "OR" and "NOT" is used.
General Rules.
1. In the absence of the relevant parenthesis in a complex condition,
the precedence (that is, binding power) of the logical operators
determines the conditions to which the specified logical operators
apply and implies the equivalent parenthesis. The order of
precedence is "NOT", "AND" , "OR". Thus, specifying "condition-1
OR NOT condition-2 AND condition-3" implies and is equivalent to
specifying "condition-1 OR (NOT condition-2) AND condition-3)".
2. Where parentheses are used in a complex condition, precedence is
used to determine the binding of conditions to logical operator.
Parentheses can, therefore, be used to depart from the normal
precedence of logical operators as specified above. Thus, the
example complex condition above can be given a different meaning
by specifying it as a "(condition-1 OR (NOT condition-2) ) AND
condition-3". (See the section Condition Evaluation Rules later
in this chapter.)
Table 4-9 indicates the ways in which conditions and logical operators
can be combined and parenthesized. There must be a one-to-one
correspondence between left and right parentheses such that each left
parenthesis is to the left of its corresponding right parenthesis.
Table 4-9 : Combinations of Conditions, Logical Operators
-------------------------------------------------------------
| | | | |
| Element | Permitted | Element can | Element can |
| | location in | be preceded | be followed |
| | conditional | by only: | by only: |
| | expression | | |
| | | | |
-------------------------------------------------------------
| | | | |
| simple- | Any | OR, NOT, | OR, AND, ) |
| condition | | AND, ( | |
| | | | |
-------------------------------------------------------------
| | | | |
| OR or AND | Not first or | simple- | simple- |
| | last | condition, | condition, |
| | | ) | NOT, ( |
| | | | |
-------------------------------------------------------------
| | | | |
| NOT | Not last | OR, AND, ( | simple- |
| | | | condition, |
| | | | ( |
| | | | |
-------------------------------------------------------------
| | | | |
| ( | Not last | OR, NOT, | simple- |
| | | AND, ( | condition, |
| | | | NOT, ( |
| | | | |
-------------------------------------------------------------
| | | | |
| ) | Not first | simple- | OR, AND, ) |
| | | condition, | |
| | | ) | |
| | | | |
-------------------------------------------------------------
Thus, the element pair "OR NOT" is permissible while the pair "NOT OR" is
not permissible; "NOT ( " is permissible while "NOT NOT" is not
permissible.
Abbreviated Combined Relation Conditions.
When simple or negated simple relation conditions are combined with
logical connectives in a consecutive sequence such that a succeeding
relation condition contains a subject or subject and relational operator
that is common with the preceding relation condition, and no parentheses
are used within such a consecutive sequence, any relation condition
except the first can be abbreviated by:
* the omission of the subject of the relation condition, or:
* the omission of the subject and relational operator of the
relation condition.
General Format.
Within a sequence of relation conditions both of the above forms of
abbreviation can be used. The effect of using such abbreviations is as
if the last preceding stated subject were inserted in place of the
omitted subject, and the last stated relational operator were inserted in
place of the omitted relational operator. The result of such implied
insertion must comply with the rules of Table 4-9. This insertion of an
omitted subject and/or relational operator terminates once a complete
simple condition is encountered within a complex condition.
For OSVS only: The order of evaluation of the conditions can be
prioritized by the use of parentheses (see example below).
The interpretation applied to the use of the word "NOT" in an abbreviated
combined relation condition is as follows:
1. For ANS85 only: If NOT is immediately followed by the word
GREATER, >, LESS, <, EQUAL, or =, excluding the relational
operators GREATER THAN OR EQUAL TO, >=, LESS THAN OR EQUAL TO, and
<=, then the word NOT is interpreted as part of the relational
operator, otherwise :
2. The "NOT" is interpreted as a logical operator and, therefore, the
implied insertion of subject or relational operator results in a
negated relation condition.
Some examples of abbreviated combined and negated combined
relation conditions and expanded equivalents follow.
Abbreviated Expanded Equivalent
Combined Relation
Condition
a > b AND NOT < c ((a > b) AND (a NOT < c)) OR (a
OR d NOT < d)
a NOT EQUAL b OR (a NOT EQUAL b) OR (a NOT EQUAL c)
c
NOT a = b OR c NOT (a = b) OR (a = c)
NOT (a GREATER b NOT ((a GREATER b) OR (a < c))
\OR < c)
NOT (a NOT > b NOT ((((a NOT > b) AND (a NOT >
AND c \AND NOT d c)) AND\ (NOT (a NOT > d))))
x > a OR y AND z x > a OR (x > y AND x > z)
x > a OR (y AND x > a OR (x > y AND x > z)
z)
x > (a OR y) AND (x > a OR x > y) AND x > z
z
x ( = a OR > b) x = a OR x > b
x = a AND ( > b x = a AND ( x > b OR x < z )
OR < z )
a EQUAL b OR NOT (a EQUAL b) OR (NOT (a GREATER OR
\GREATER OR EQUAL EQUAL c) ) OR \(a GREATER OR EQUAL
c \OR d d)
a EQUAL b OR NOT (a EQUAL b) OR (NOT (a >= c) ) OR
>=c \OR d (a >= d)
Condition Evaluation Rules.
Parentheses can be used to specify the order in which individual
conditions of complex conditions are to be evaluated when it is necessary
to depart from the implied evaluation precedence.
Conditions within parentheses are evaluated first, and, within nested
parentheses, evaluation proceeds from the least inclusive condition to
the most inclusive condition. When parentheses are not used, or
parenthesized conditions are at the same level of inclusiveness, the
following hierarchical order of logical evaluation is implied until the
final truth value is determined:
1. For ANS85 only: Values are established for arithmetic expressions
and functions if and when the conditions containing them are
evaluated. Similarly, negated conditions are evaluated if and
when it is necessary to evaluate the complex condition that they
represent. (See Formation And Evaluation Rules in the section
Arithmetic Expressions in this chapter) .
2. Truth values for simple conditions are established in the
following order:
relation (following the expansion of any abbreviated
relation condition)
class
condition-name
switch-status
sign
3. Truth values for negated conditions are established.
4. Truth values for combined conditions are established: "AND"
logical operators, followed by "OR" logical operators.
5. Truth values for negated combined conditions are established.
6. When the sequence of evaluation is not completely specified by
parentheses, the order of evaluation of consecutive operations of
the same hierarchical level is from left to right.
Common Phrases
In the statement descriptions that follow, several phrases appear
frequently: the ROUNDED phrase, the ON SIZE ERROR phrase, the NOT ON
SIZE ERROR phrase (ANS85 only). and the CORRESPONDING phrase. Each of
these phrases is discussed below.
In the following paragraphs, the term "resultant-identifier" refers to
that identifier associated with the result of an arithmetic operation.
The ROUNDED Phrase.
If, after decimal point alignment, the number of places in the fraction
of the result of an arithmetic operation is greater than the number of
places provided for the fraction of the resultant-identifier, truncation
is relative to the size provided for the resultant-identifier. When
rounding is requested, the absolute value of the resultant-identifier is
increased by one whenever the most significant digit of the excess is
greater than or equal to five.
When the low-order integer positions in a resultant-identifier are
represented by the character "P" in the PICTURE for the resultant-
identifier, rounding or truncation occurs relative to the rightmost
integer position for which storage is allocated.
For OSVS, VSC2 and MF only: In a floating-point arithmetic operation,
the ROUNDED phrase is treated as documentary; the result of a
floating-point operation is always rounded .
The ON SIZE ERROR Phrase and (NOT ON SIZE ERROR Phrase) (ANS85 only).
If, after decimal point alignment, the absolute value of a result of an
arithmetic operation exceeds the largest value that can be contained in
the associated resultant-identifier, a size error condition exists.
Division by zero always causes a size error condition. Note that the
results of division by zero when no ON SIZE ERROR phrase is specified,
are unpredictable. The size error condition applies only to the final
results, except in MULTIPLY and DIVIDE statements, in which case the size
error condition applies to the intermediate results as well.
For ANS85 and MF only: Violation of the rules for the evaluation of
exponentiation always terminates the arithmetic operation and always
causes a size error condition.
If the ROUNDED phrase is specified, rounding takes place before checking
for size error. When such a size error condition occurs, the subsequent
action depends on whether or not the SIZE ERROR phrase is specified, as
follows:
ON SIZE ERROR Phrase Not Specified.
When a size error condition occurs, the value of those resultant-
identifier(s) affected is undefined. Values of resultant-identifier(s)
for which no size error condition occurs are unaffected by size errors
that occur for other resultant-identifier(s) during execution of this
operation.
For ANS85 only: After completion of the arithmetic operation, control is
transferred to the end of the arithmetic statement and the NOT ON SIZE
phrase, if specified, is ignored .
Results of division by zero, when no ON SIZE ERROR is specified, are
unpredictable. You can avoid this by using the CHECKDIV compiler
directive and O run time switch. See your COBOL System Reference for
details.
ON SIZE ERROR Phrase Specified.
When a size error condition occurs, then the values of resultant-
identifier(s) affected by the size errors are not altered. Values of
resultant-identifier(s) for which no size error condition occurs are
unaffected by size errors that occur for other resultant-identifier(s)
during execution of this operation. After completion of the execution of
this operation, the imperative statement in the SIZE ERROR phrase is
executed.
For the ADD statement with the CORRESPONDING phrase and the SUBTRACT
statement with the CORRESPONDING phrase, if any of the individual
operations produces a size error condition, the imperative statement in
the ON SIZE ERROR phrase is not executed until all of the individual
additions or subtractions are completed.
For ANS85 only: If an ON SIZE ERROR condition occurs, any NOT ON SIZE
ERROR phrase is ignored whether or not an ON SIZE ERROR phrase is
specified .
For ANS85 only: When both ON SIZE ERROR and NOT ON SIZE ERROR phrases
are specified, and the statement in the phrase that is executed does not
contain any explicit transfer of control, then, if necessary, an implicit
transfer of control is made after execution of the phrase to the end of
the arithmetic statement.
For ANS85 only: The NOT ON SIZE ERROR Phrase.
If the NOT ON SIZE ERROR phrase is specified for an arithmetic operation
statement, and after execution of that statement a size error condition
(as defined above) does not exist, then the NOT ON SIZE ERROR phrase, if
specified is executed. The ON SIZE ERROR phrase, if specified, is
ignored, and the imperative statement associated with it is not executed.
The CORRESPONDING Phrase.
In the text that follows, d1 and d2 must each be identifiers that refer
to group items. A pair of data items, one from d1 and one from d2
correspond if the following conditions exist:
1. A data item in d1 and a data item in d2 are not designated by the
key word FILLER and have the same data-name and the same
qualifiers up to, but not including, d1 and d2.
2. At least one of the data items is an elementary data item and the
resulting move is legal according to the move rules in the case of
a MOVE statement with the CORRESPONDING phrase, and both of the
data items are elementary numeric data items in the case of the
ADD statement with the CORRESPONDING phrase or the SUBTRACT
statement with the CORRESPONDING phrase.
3. The description of d1 and d2 must not contain level-number 66, 77,
78 (MF only) or 88 or the USAGE IS INDEX clause.
4. A data item that is subordinate to d1 or d2 and contains a
REDEFINES, RENAMES, OCCURS, USAGE IS INDEX, USAGE IS
PROCEDURE-POINTER or USAGE IS POINTER (MF and VSC2 only) clause is
ignored, as well as those data items subordinate to the data item
that contains the REDEFINES, RENAMES, OCCURS, USAGE IS INDEX,
USAGE IS PROCEDURE-POINTER, or USAGE IS POINTER (MF and VSC2 only)
clause. However, d1 and d2 can have REDEFINES or OCCURS clauses
or be subordinate to data items with REDEFINES or OCCURS clauses.
For ANS85 only: Neither d1 or d2 can be reference modified <.
5. The name of each data item which satisfies the above conditions
must be unique after application of the implied qualifiers.
Arithmetic Statements.
The arithmetic statements are the ADD, COMPUTE, DIVIDE, MULTIPLY and
SUBTRACT statements. Common features are as follows:
1. The data descriptions of the operands need not be the same; any
necessary conversion and decimal point alignment are supplied
throughout the calculation.
2. The maximum size of each operand is 18 decimal digits. The
composite of operands, which is a hypothetical data item resulting
from the superimposition of specified operands in a statement
aligned on their decimal points (see the sections The ADD
Statement, The DIVIDE Statement, The MULTIPLY Statement and The
SUBTRACT Statement later in this chapter) must not contain more
than 18 decimal digits.
Overlapping Operands.
When a sending and a receiving item in a statement share a part of their
storage areas, yet are not defined by the same data description entry,
(ANS85 only) the result of the execution of such a statement is
undefined.
For MF only: Overlapping moves are detected at compile time only when
the MOVE verb is used and neither operand uses reference modification or
subscripting. Forward overlapping moves result in a warning message, if
you set the directive WARNING"3". Any other types result in flagging
messages, if you set the directive FLAG"dialect", where "dialect" is
anything but OSVS. Other operations resulting in sending and receiving
items sharing the same memory are not detected.
For MF only: Although portability of COBOL source code is only
guaranteed when no overlapping MOVE statements occur in your source
program, this COBOL system does allow such statements. The behavior of
such statements is sensitive to the BYTE-MODE-MOVE directive. See your
COBOL System Reference for details on this directive.
Multiple Results in Arithmetic Statements.
The ADD, COMPUTE, DIVIDE, MULTIPLY and SUBTRACT statements can have
multiple results. Such statements behave as though they had been written
in the following way:
1. A statement which accesses all data items that are part of the
initial evaluation of the statement, performs all arithmetic
necessary to arrive at the result to be stored in the receiving
items, and stores that result in a temporary storage location.
2. A sequence of statements transferring or combining the value of
this temporary location with each single resultant data item.
These statements are considered to be written in the same
left-to-right sequence in which the multiple results are listed.
The result of the statement:
ADD a, b, c TO c, d (c), e
is equivalent to:
ADD a, b, c GIVING temp
ADD temp TO c
ADD temp TO d (c)
ADD temp TO e
and the result of the statement:
MULTIPLY a(i) BY i, a(i)
is equivalent to:
MOVE a(i) to temp
MULTIPLY temp by i
MULTIPLY temp BY a(i)
where temp is an intermediate result item provided by your COBOL system.
Incompatible Data.
Except for the class condition (see the section Class Condition in this
chapter), when the contents of a data item are referenced in the
Procedure Division and the contents of that data item are not compatible
with the class specified for that data item by its PICTURE clause or
function definition (ANS85 only) then the result of such a reference is
undefined.
For MF only: The results of referencing a numeric field that contains
nonnumeric, or otherwise invalid data, are undefined. Such conditions
may be detected, and give an error at run-time. See your COBOL System
Reference for details of the +F run-time switch .
For MF only: When an alphabetic field which contains non-alphabetic
data is referenced, your program will continue execution, but results may
be undefined.
Signed Receiving Items.
When the receiving item in an arithmetic statement or a MOVE statement is
a signed numeric or a signed numeric edited item, the sign is moved into
the receiving item independently of any truncation of the absolute
numeric data. It is possible, therefore, for the numeric value to be
zero but for the sign to be negative.
MPE/iX 5.0 Documentation