HP 3000 Manuals

Common Phrases [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

Common Phrases 

The  NOT, ROUNDED, SIZE ERROR, and CORRESPONDING phrases are common
phrases used in several PROCEDURE DIVISION statements.  In order to avoid
describing each of these phrases each time they appear in a particular
statement, they are described just once in the following paragraphs.

In the description that follows, the term resultant identifier means the
identifier associated with a result of an arithmetic operation.

NOT Phrases 

The  NOT phrases are a feature of the 1985 ANSI COBOL standard.

You can use NOT phrases with the statements that have conditionally
executed exception phrases.  The imperative statements in the NOT phrases
execute when the exception does not occur.  Table 8-5  lists the new
NOT phrases and their associated verbs.

          Table 8-5.  NOT Phrases and Associated Verbs 

--------------------------------------------
|                           |              |
|          Phrase           |  Statement   |
|                           |              |
--------------------------------------------
|                           |              |
|  NOT AT END-OF-PAGE       | WRITE        |
|                           |              |
--------------------------------------------
|                           |              |
|  NOT AT END               | READ         |
|                           | RETURN       |
|                           |              |
--------------------------------------------
|                           |              |
|  NOT INVALID KEY          | DELETE       |
|                           | READ         |
|                           | REWRITE      |
|                           | START        |
|                           | WRITE        |
|                           |              |
--------------------------------------------
|                           |              |
|  NOT ON EXCEPTION         | CALL         |
|                           |              |
--------------------------------------------
|                           |              |
|  NOT ON OVERFLOW          | STRING       |
|                           | UNSTRING     |
|                           |              |
--------------------------------------------
|                           |              |
|  NOT ON SIZE ERROR        | ADD          |
|                           | COMPUTE      |
|                           | DIVIDE       |
|                           | MULTIPLY     |
|                           | SUBTRACT     |
|                           |              |
--------------------------------------------
|                           |              |
|  NOT ON INPUT ERROR       | ACCEPT       |
|                           |              |
--------------------------------------------

ROUNDED Phrase 

The ROUNDED phrase consists entirely of the keyword, ROUNDED.

In an arithmetic operation, if, after decimal point alignment, there are
more decimal places in the fraction of the result than is specified for
the resultant identifier, truncation is performed on the result.  The
number of digits truncated is dependent upon the number of decimal places
specified for the fractional part of the resultant identifier.

If you want to round the result before truncation occurs, you can use the
ROUNDED option.

If the ROUNDED phrase is specified in an arithmetic operation, the
absolute value of the resultant identifier is increased by one whenever
the most significant digit of the excess portion of the result is greater
than or equal to 5.  The excess portion is then truncated.

When the low-order integer positions in a resultant identifier are
represented by the P character in the PICTURE clause of that resultant
identifier, rounding occurs relative to the rightmost integer position
for which storage is allocated.

SIZE ERROR Phrase 

The SIZE ERROR phrase has the format

[ON SIZE ERROR imperative-statement]

where imperative-statement is one or more imperative statements.

If, after decimal point alignment, the number of digits in a result
exceeds the number of digits specified for the associated resultant
identifier, a SIZE ERROR condition exists.

The imperative-statement is executed if a SIZE ERROR condition occurs.

The SIZE ERROR condition applies only to the final result of most
arithmetic operations; it applies to intermediate results, however, when
the MULTIPLY, DIVIDE, and COMPUTE statements are used.

Note that division by 0 (zero) and violation of the rules for
exponentiation always forces a SIZE ERROR condition.

If the ROUNDED phrase is specified in an arithmetic operation, rounding
is done before a SIZE ERROR check is performed.


NOTE When a SIZE ERROR condition occurs and the SIZE ERROR phrase is not specified, the values of any resultant identifiers affected are undefined.
If other resultant identifiers are involved in a particular arithmetic operation for which a SIZE ERROR condition occurs, their values are unaffected. Only the resultant identifiers for which the SIZE ERROR occurs have undefined values. Example 1 If the following arithmetic operation forces a SIZE ERROR condition for B, but not for C, only B has an undefined value: ADD A TO B, C When the SIZE ERROR phrase is specified for an arithmetic operation and a SIZE ERROR condition exists for the values of one or more of the resultant identifiers involved, their values remain as they were before the operation was executed. Values of other resultant identifiers involved in the operation are unaffected by size errors. Therefore, their values are changed according to the arithmetic operation specified. The SIZE ERROR phrase includes an imperative-statement following the words SIZE ERROR. This statement is executed following the occurrence of a size error in an arithmetic statement for which the SIZE ERROR phrase is specified. Example 2 WORKING-STORAGE SECTION. 01 SIZE-ERR. 02 NOTIFY PIC X(10) VALUE 'SIZE ERROR'. 02 PARAMETERS. 03 PARM-1 PIC Z(18) VALUE 0. 03 PARM-2 PIC Z(18) VALUE 0. PROCEDURE DIVISION. : ADD A B TO C D ROUNDED ON SIZE ERROR PERFORM NOTIFICATION. : NOTIFICATION. MOVE C TO PARM-1. MOVE D TO PARM-2. WRITE SIZE-ERR AFTER ADVANCING 1 LINE. : If an ADD or SUBTRACT statement uses the CORRESPONDING phrase as well as the SIZE ERROR phrase and an operation produces a size error condition, the imperative statement in the SIZE ERROR phrase is not executed until all individual additions or subtractions are completed. CORRESPONDING Phrase The CORRESPONDING phrase consists entirely of the word CORRESPONDING, or of the equivalent abbreviation, CORR. The purpose of the CORRESPONDING phrase is to allow you to add, subtract, or move a data item subordinate to a group item to a data item subordinate to some other group item. Two data items are said to correspond if three conditions are met. For purposes of description, assume that D1 and D2 are group items. A data item from D1 is said to correspond to a data item from D2 if: 1. Both of the data items have the same name, the name is not FILLER, and both have the same qualifiers up to, but not including D1 and D2. 2. When the CORRESPONDING phrase is being used in a MOVE statement, at least one of the data items is an elementary data item; when the CORRESPONDING phrase is used in an ADD or SUBTRACT statement, both data items are elementary data items. 3. The descriptions of D1 and D2 do not contain a 66, 77, or 88 level number and do not contain a USAGE IS INDEX clause. Any data item that is a candidate for use in a CORRESPONDING phrase is ignored if it contains a REDEFINES, RENAMES, OCCURS, or USAGE IS INDEX clause, even if it meets the conditions above. Furthermore, any data items subordinate to such a data item are also ignored. These restrictions do not apply to D1 and D2, except as noted in condition 3 above. Example 01 FIRST-DATA. 02 ENTRY-1. 03 ENTRY-1A PIC 9(5)V99. 03 ENTRY-1B PIC 9(3)V99. 02 ENTRY-2 PIC X(30). 01 SECOND-DATA. 02 ENTRY-1. 03 ENTRY-1A PIC 99V99. 03 ENTRY-1B PIC 999. 02 FINISH PIC X(20). ENTRY-1A of FIRST-DATA corresponds to ENTRY-1A of SECOND-DATA, and ENTRY-1B of FIRST-DATA corresponds to ENTRY-1B of SECOND-DATA. ENTRY-1 of FIRST-DATA does not correspond to ENTRY-1 of SECOND-DATA because of the second condition of correspondence. The ADD statement below uses the CORRESPONDING phrase to add ENTRY-1A of FIRST-DATA to ENTRY-1A of SECOND-DATA, and ENTRY-1B of FIRST-DATA to ENTRY-1B of SECOND-DATA. The results are stored in ENTRY-1A and ENTRY-1B of SECOND-DATA. ADD CORRESPONDING FIRST-DATA TO SECOND-DATA.
NOTE There is a limit of approximately 500 matching pairs allowed in a single MOVE CORRESPONDING statement. Multiple MOVEs are necessary to exceed this limit. Compiler errors 390 and 457 are given for this condition.


MPE/iX 5.0 Documentation