[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
When you combine simple or negated simple conditions in a consecutive sequence, you can abbreviate any of the relation conditions except the first. You do this by either:
The general format for abbreviated combined relation conditions is as follows:
The evaluation of a sequence of combined relation conditions proceeds as if the last preceding subject appears in place of the omitted subject and the last preceding relational operator appears in place of the omitted relational operator. The result of these substitutions must form a valid condition. (See Table 6-5.)
When the word NOT appears in a sequence of abbreviated conditions, its treatment depends upon the word that follows it. NOT is considered part of the relational operator when immediately followed by: GREATER, >, LESS, <, EQUAL, or =. Otherwise, NOT is considered a logical operator that negates the relation condition.
Table 6-6 shows abbreviated combined (and negated combined) relation conditions and their expanded equivalents:
Abbreviated Combined Relation Condition |
Expanded Equivalent |
---|---|
a > b AND NOT < c OR d | ((a > b) AND (a NOT < c)) OR (a NOT < d) |
a NOT = b OR c | (a NOT = b) OR (a NOT = c) |
NOT a = b OR c | (NOT (a = b)) OR (a = c) |
NOT (a GREATER b OR < c) | NOT ((a GREATER b) OR (a < c)) |
a / b NOT = c AND NOT d | ((a / b) NOT = c) AND (NOT ((a / b) NOT = d)) |
NOT (a NOT > b AND c AND NOT d) | NOT ((((a NOT > b) AND (a NOT > c)) AND (NOT (a NOT > d)))) |
Parentheses can specify the evaluation order in complex conditions. Conditions in parentheses are evaluated first. In nested parentheses, evaluation starts with the innermost set of parentheses. It proceeds to the outermost set.
Conditions are evaluated in a hierarchical order when there are no parentheses in a complex condition. This same order applies when all sets of parentheses are at the same level (none are nested). The hierarchy is shown in the following list:
In the absence of parentheses, the order of evaluation of consecutive
operations at the same hierarchical level is from left to right.
6.6 Common Rules and Options for Data Handling
This section describes the rules and options that apply when statements handle data. Data handling includes the following:
The arithmetic statements begin with the verbs ADD, COMPUTE, DIVIDE, MULTIPLY, and SUBTRACT. When an operand in these statements is a data item, its PICTURE must be numeric and specify no more than 31 digit positions on Alpha or I64 (18 on VAX). However, operands do not have to be the same size, nor must they have the same USAGE. Conversion and decimal point alignment occur throughout the calculation.
When you write an arithmetic statement, you specify one or more data items to receive the results of the operation. These data items are called resultant identifiers. However, the evaluation of each arithmetic statement can also use an intermediate data item. An intermediate data item is a compiler-supplied signed numeric data item that the program cannot access. It stores the results of intermediate steps in the arithmetic operation before moving the final value to the resultant identifiers.
When the final value of an arithmetic operation is moved to the
resultant identifiers, it is transferred according to MOVE statement
rules. Rounding and size error condition checking occur just before
this final move. (See the Section 6.8.22 statement, Section 6.6.4, ON SIZE ERROR Phrase, and
Section 6.6.3, ROUNDED Phrase.)
6.6.2 Multiple Receiving Fields in Arithmetic Statements
An arithmetic statement can move its final result to more than one data item. In this case, the statement is said to have multiple receiving fields (or multiple results). The statement operates as if it had been written as a series of statements. The following example illustrates these steps. The first statement in the example is equivalent to the four that follow it. (Temp is an intermediate data item.)
ADD a, b, c TO c, d (c), e ADD a, b, c GIVING temp ADD temp TO c ADD temp TO d (c) ADD temp TO e |
The ROUNDED phrase allows you to specify rounding at the end of an arithmetic operation. The rounding operation adds 1 to the absolute value of the low-order digit of the resultant identifier if the absolute value of the next least significant (lower-valued) digit of the intermediate data item is greater than or equal to 5.
When the PICTURE string of the resultant identifier represents the low-order digit positions with the P character, rounding or truncation is relative to the rightmost integer position for which the compiler allocates storage. Therefore, when PIC 999PPP describes the item, the value 346711 is rounded to 347000.
If you do not use the ROUNDED phrase, any excess low-order digits in
the arithmetic result are truncated when the result is moved to the
resultant identifiers.
6.6.4 ON SIZE ERROR Phrase
The ON SIZE ERROR phrase allows you to specify an action for your program to take when a size error condition exists.
The NOT ON SIZE ERROR phrase allows you to specify an action for your program to take when a size error condition does not exist.
The format is as follows:
stment is an imperative statement.
Size error checking occurs after decimal point alignment. Rounding occurs before size error checking. Also, truncation of rightmost digits occurs before size error checking.
A size error condition is caused by the following:
In the second case above, the size error condition affects the contents of only those resultant identifiers for which the size error exists.
When a size error condition occurs and the statement contains an ON SIZE ERROR phrase:
When a size error condition occurs and the statement does not contain an ON SIZE ERROR phrase:
When a size error condition does not occur:
Previous | Next | Contents | Index |