Previous Topic Next topic Print topic


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.

Previous Topic Next topic Print topic