HP 3000 Manuals

Common Features of Arithmetic Statements [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

Common Features of Arithmetic Statements 

The five arithmetic statements, ADD, SUBTRACT, MULTIPLY, DIVIDE, and
COMPUTE have the following features in common:

   1.  The data descriptions of operands in an arithmetic statement need
       not be the same.

       If operands are of mixed types, the compiler generates any data
       conversion routines necessary to format the data.  Note that this
       does increase the size of the code space.

       If the operands are already defined as COMPUTATIONAL SYNCHRONIZED,
       the compiler does not have to generate conversion routines.  This
       reduces the object program size and its execution time.
       Therefore, to maximize efficiency of arithmetic operations,
       remember to define the operands as being COMPUTATIONAL
       SYNCHRONIZED or with a usage of COMPUTATIONAL-3.

       For more information, see the HP COBOL II/XL Programmer's Guide.

   2.  The maximum size of each operand is 18 digits.  The composite of
       operands must not contain more than 18 decimal digits.

       The composite of operands is the hypothetical data item resulting
       from the superimposition of specified operands in an arithmetic
       statement after the operands have been aligned on their decimal
       points. 

       For example, in format 1 of the ADD statement, the composite of
       operands is determined by using all of the operands in a given
       statement.

       Therefore, if A = 1234.567, B = 1.2359, and C = 10340.77, the
       composite of operands of the statement ADD A, B TO C is
       10340.2359.

       This number was arrived at by selecting the operand with the
       greatest number of digits to the right of the decimal point (in
       this case, 1.2359), and then the operand with the greatest number
       of digits to the left of the decimal point (which is 10340.77).

       These two operands were then superimposed, with the larger number
       to the left or right of the decimal point masking the smaller.

   3.  Arithmetic statements can have multiple results.  For example, the
       following ADD statement gives the multiple results, A + B, A + C,
       and A + D:

            ADD A TO B, C, D.

       Such statements behave as though they had been written in the
       following way:

          a.  A statement was first written that performs the specified
              arithmetic operation, and stores the results in a temporary
              location.

          b.  A sequence of statements was then written that transfers or
              combines the value in the temporary location with each of
              the single data items specified as a result in the original
              arithmetic statement.  This hypothetical sequence of
              statements was written to perform the transferring or
              combining of the temporary value in the same left-to-right
              sequence as the multiple results are listed.

Example 

The following example illustrates how a temporary location is used in an
ADD statement:

     ADD A, B, C TO C, D, E

The above ADD statement is equivalent to the following ADD statements,
where TEMP is a temporary location that stores the intermediate result:

     ADD A,B,C GIVING TEMP
               ADD TEMP TO C
               ADD TEMP TO D
               ADD TEMP TO E

Overlapping Operands and Incompatible Data 

When a sending and a receiving data item in an arithmetic statement or an
INSPECT, MOVE, SET, STRING, or UNSTRING statement share a part of their
storage areas, the result of the execution of such a statement is
undefined.

Furthermore, except for a class condition, 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, the sign, or the range of
values specified by its PICTURE clause, the result of such a reference is
undefined.

Variable-Length Receiving Items 

 In ANSI COBOL'85, when a receiving item is a variable-length data item 
and   contains the object of the DEPENDING ON phrase, the maximum length 
of the  item is used.   

In ANSI COBOL'74, the length is computed using the object of the
DEPENDING ON phrase.



MPE/iX 5.0 Documentation