[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

6.3.3 Explicit and Implicit Attributes

An explicit attribute is an attribute the program explicitly specifies. If the program does not explicitly specify an attribute, the attribute assumes a default; it is then an implicit attribute.

For example, a program need not specify USAGE for a data item. If it does not, the data item's implicit usage is DISPLAY.

6.3.4 Explicit and Implicit Scope Terminators

Scope terminators delimit the scope of some Procedure Division statements as described in Section 6.1.4.

The following are explicit scope terminators:

END-ACCEPT END-ADD END-CALL
END-COMPUTE END-DELETE END-DIVIDE
END-EVALUATE END-IF END-MULTIPLY
END-PERFORM END-READ END-RETURN
END-REWRITE END-SEARCH END-START
END-STRING END-SUBTRACT END-UNSTRING
END-WRITE    

The following are implicit scope terminators:

  • At the end of a sentence the separator period terminates the scope of all previously unterminated statements.
  • In a statement containing another statement the next phrase of the containing statement after the end of the contained statement terminates the scope of all unterminated contained statements. Examples are ELSE and WHEN.

6.4 Arithmetic Expressions

Whenever the term arithmetic expression appears in Procedure Division rules, it refers to one of the following:

  • An identifier of a numeric elementary item
  • A numeric literal
  • A figurative constant ZERO (ZEROS, ZEROES)
  • Two or more of the above separated by arithmetic operators
  • Two or more arithmetic expressions separated by arithmetic operators
  • An arithmetic expression enclosed in parentheses

A unary operator (a sign) can precede any arithmetic expression.

The identifiers and literals in an arithmetic expression must represent either of the following:

  • Numeric elementary items
  • Numeric literals on which arithmetic can be performed

Evaluation rules for arithmetic expressions depend on whether the mode of arithmetic in effect is native or standard.

6.4.1 Arithmetic Operators

Arithmetic expressions can use five binary and two unary arithmetic operators. A space must precede each operator and follow each binary operator.

The operators are as follows:

Binary Arithmetic Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
** Exponentiation
Unary Arithmetic Operator Meaning
+ The effect of multiplication by +1
- The effect of multiplication by -1

6.4.2 Formation and Evaluation of Arithmetic Expressions

The following rules apply regardless of the mode of arithmetic that is in effect.

Parentheses can be used to specify the order in which elements in an arithmetic expression are evaluated. Expressions within parentheses are evaluated first. If you nest sets of parentheses, evaluation starts with the innermost set of parentheses and proceeds to the outermost set.

If the arithmetic expression contains no parentheses, the compiler evaluates arithmetic operators in the following hierarchical order:

First Unary plus and minus
Second Exponentiation
Third Multiplication and division
Fourth Addition and subtraction

This order also applies within a single set of parentheses.

If two or more operators are at the same hierarchical level, and parentheses do not specify the sequence of operations, evaluation proceeds from left to right.

Parentheses can eliminate ambiguities in logic when there are consecutive operations at the same hierarchical level, or change the normal hierarchical sequence of evaluation.

Consider the following expression:


(3 * ITEMA - 2) / ((4 + ITEMB) * -ITEMA - ITEMC ** 2)

The order of evaluation is as follows:

  1. 4 + ITEMB
  2. -ITEMA
  3. 3 * ITEMA
  4. (The results of step 3) - 2
  5. ITEMC ** 2
  6. (The results of step 1) * (the results of step 2)
  7. (The results of step 6) - (the results of step 5)
  8. (The results of step 4) / (the results of step 7)

Each left parenthesis in an arithmetic expression must have a matching right parenthesis, and each right parenthesis must have a matching left parenthesis.

If the first operator in an arithmetic expression is a unary operator, a left parenthesis (() must immediately precede it when the arithmetic expression immediately follows an identifier or another arithmetic expression. For example:


CALL "OTHERPROG" USING ITEMA (-ITEMB) ITEMC.

The following rules apply to the evaluation of exponentiation:

  1. If the value of an expression to be raised to a power is zero, the exponent value must be greater than zero. Otherwise, the size error condition exists. (See Section 6.6.4.)
  2. If the evaluation yields both a positive and negative real number, the positive number is the result.
  3. If the evaluation yields no real number, the size error condition exists.

If the evaluation of the arithmetic expression results in an attempted division by zero, the size error condition exists.

When a statement with an arithmetic expression does not refer to a resultant identifier, the compiler stores the results of the arithmetic expression in an intermediate data item. (See Section 6.6.1.)

6.4.3 Standard Arithmetic (Alpha, I64)

When a floating-point data item is an operand in an arithmetic expression or an arithmetic statement, the rules for evaluation are described in Section 6.4.4.1.1

When standard arithmetic is in effect, the following rules apply:

  1. Any operand of an arithmetic expression that is not already contained in a standard intermediate data item is converted into a standard intermediate data item.
  2. The size error condition is raised if the value is too large or too small to be contained in a standard intermediate data item.

A standard intermediate data item is of the class numeric and the category numeric. It is the unique value zero or an abstract, signed, normalized decimal floating-point temporary data item.

A standard intermediate data item has the unique value of zero or a value whose magnitude is in the range 10**-100 through 10**99 - 10**67, that is, (.100 000 000 000 000 000 000 000 000 000 00E-99) through (.999 999 999 999 999 999 999 999 999 999 99E+99)2 inclusive, with a precision of 32 decimal digits.

When the value of a standard intermediate data item is not zero, the fraction contains no digits to the left of the decimal point and contains a digit other than zero to the immediate right of the decimal point.

A standard intermediate data item is rounded to 31 digits in the situations listed below.

  1. When a standard intermediate data item is compared.
  2. When a standard intermediate data argument is the argument of a function and there is no equivalent arithmetic expression defined for the rules of the function, unless otherwise specified in the rules for a function or unless situation 1, above, applies.
  3. When a standard intermediate data item is being moved to a resultant-identifier for which the ROUNDED phrase has not been specified. Rounding of a standard intermediate data item may cause the size error condition to be raised.3

When a standard intermediate data item is being moved to a resultant-identifier for which the ROUNDED phrase is specified, the number of digits to which rounding occurs is as specified in the ROUNDED phrase.

When arithmetic expressions using addition, subtraction, multiplication, division, exponentiation, unary plus, and unary minus are evaluated, the exact result is truncated to 32 significant digits, normalized, and stored in a standard intermediate data item.

Note

1 A floating-point data item has one of these usages: COMP-1, COMP-2, FLOAT-SHORT, FLOAT-LONG, or FLOAT-EXTENDED.

2 The blanks are added for readability.

3 These rules are intended to eliminate excessive rounding and to ensure that rounding occurs once at the end of the evaluation of nested arithmetic expressions.


Previous Next Contents Index