MULTIPLY Statement
The MULTIPLY statement performs arithmetic multiplication, allowing for the storage of the product in one or more data items.
Format 1
The Format 1 MULTIPLY Statement MULTIPLY's an initial numeric data item BY one or more numeric data items, and moves the result of the MULTIPLY operation into the initial numeric data item. The result may be optionally ROUNDED.
MULTIPLY numeric-1 BY { numeric-data-2 [ROUNDED] } ...
[ ON SIZE ERROR statement-1 ]
[ NOT ON SIZE ERROR statement-2 ]
[ END-MULTIPLY ]
Format 2
The Format 2 MULTIPLY Statement MULTIPLY's an initial numeric data item BY a second numeric data item, and moves the result of the MULTIPLY operation into the data element(s) following the GIVING clause. The result may be optionally ROUNDED.
MULTIPLY numeric-3 BY numeric-data-4
GIVING { numeric-data-5 [ROUNDED] } ...
[ ON SIZE ERROR statement-1 ]
[ NOT ON SIZE ERROR statement-2 ].
[ END-MULTIPLY ]
Syntax:
numeric-nis a literal or data item that is numeric.numeric-data-nis a numeric data item.statement-nis an imperative statement.
General Rules:
- Format 1, and Format 2 of the
MULTIPLYoperation allow multiple receiving fields. TheROUNDEDclause is applied when aMULTIPLYoperation produces a result that includes more decimal places than are included in the description of the data item given to hold the final result of the arithmetic operation. - For rules regarding the
ROUNDEDclause, see the entry for ROUNDED in the Common General Rules section. - The
SIZE ERRORexception is triggered if theON SIZE ERRORclause is present and if the receiving field is not large enough to accommodate the result of theMULTIPLYfunction. - For rules regaring the
ON SIZE ERRORclause, see the entry for ON SIZE ERROR in the Common General Rules section.
Code Sample:
IDENTIFICATION DIVISION.
PROGRAM-ID. MULTIPLY-1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
78 CONST-1 VALUE 10.
78 CONST-2 VALUE 25.
77 NUMERIC-1 PIC 99.
77 NUMERIC-2 PIC 99999.
77 NUMERIC-3 PIC 99999.
77 DUMMY PIC X.
PROCEDURE DIVISION.
MAIN.
MOVE CONST-1 TO NUMERIC-1.
MOVE CONST-2 TO NUMERIC-2.
MULTIPLY NUMERIC-1 BY NUMERIC-2 ROUNDED
ON SIZE ERROR
DISPLAY "FORMAT 1 SIZE ERROR!" LINE 3 COL 10
NOT ON SIZE ERROR
DISPLAY NUMERIC-2 LINE 3 COL 10
END-MULTIPLY.
*
MOVE CONST-1 TO NUMERIC-1.
MOVE CONST-2 TO NUMERIC-2.
MULTIPLY NUMERIC-1 BY NUMERIC-2
GIVING NUMERIC-3 ROUNDED
ON SIZE ERROR
DISPLAY "FORMAT 2 SIZE ERROR!" LINE 4 COL 10
NOT ON SIZE ERROR
DISPLAY NUMERIC-3 LINE 4COL 10
END-MULTIPLY.
DISPLAY "MULTIPLY-1 FINISHED!" LINE 10 COL 10.
ACCEPT DUMMY LINE 10 COL 30.
STOP RUN.