The MULTIPLY statement multiplies numeric items and sets the values of data items equal to the results.

The MULTIPLY statement is used to multiply numeric items together. Both formats work slightly differently and each is described in the correspondingly numbered area.

The first format is used to multiply a field or value by another field or value. The product of the field(s) or value(s) listed between MULTIPLY and BY is computed and multiplied by the value of the field(s) following the BY. The answer is stored in the individual field.

MULTIPLY {indentifier-1 or literal-1}...BY {indentifier-2 [ROUNDED]}... [ON SIZE ERROR imperative-statement-1] [NOT ON SIZE ERROR imperative-statement-2] [END-MULTIPLY] |

The value of identifier-1 or literal-1 is multiplied by the value of identifier-2; the product is then placed in identifier-2. For each successive occurrence of identifier-2, the multiplication takes place in the left-to-right order in which identifier-2 is specified.

Let see some example,

MULTIPLY A BY B |

- The value in A is multiplied by the value in B and the result is stored in B. The value in A is unchange.

MULTIPLY C BY D E |

- The value in C is multiplied by the value in D, storing the answer in D and the value of C is also multiplied by E, storing the value in F. The value in C is unchanged.

The second format is used by multiply field(s) or value(s) by one another field or value, storing the answer in a different field. The field(s) or value(s) listed between MULTIPLY and GIVING are multiplied and stored in the field(s) following the GIVING.

MULTIPLY {indentifier-1 or literal-1}...BY {indentifier-2 or literal-2} GIVING {identifier-3 [ROUNDED]}... [ON SIZE ERROR imperative-statement-1] [NOT ON SIZE ERROR imperative-statement-2] [END-MULTIPLY] |

The value of identifier-1 or literal-1 is multiplied by the value of identifier-2 or literal-2. The product is then stored in the data items referenced by identifier-3.

MULTIPLY A BY B GIVING C |

- The value in A is multiplied by the value in B and the result is stored in C. The values in A and B are unchanged.

Optional phrases in MULTIPLY operation:

- The fields to be multiplied must have numeric pictures, that is, they can only have the characters 9, S, and V in their PIC clauses.

- Receiving fields may be either numeric or numeric edited fields.

- Use the SIZE ERROR clause to detect field overflow on the receiving field.

- In both formats, the mathematically correct results are computed, but if the receiving field is too short in either the integer or decimal portion, the result will be truncated, the integer on the left and the decimal on the right.

Including the ROUNDED phrase will result the answer field being rounded instead of truncating. Rounding is always done in the least significant portion of the answer.

* If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!*