Skip to content

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:

  1. numeric-n is a literal or data item that is numeric.
  2. numeric-data-n is a numeric data item.
  3. statement-n is an imperative statement.

General Rules:

  1. Format 1, and Format 2 of the MULTIPLY operation allow multiple receiving fields. The ROUNDED clause is applied when a MULTIPLY operation 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.
  2. For rules regarding the ROUNDED clause, see the entry for ROUNDED in the Common General Rules section.
  3. The SIZE ERROR exception is triggered if the ON SIZE ERROR clause is present and if the receiving field is not large enough to accommodate the result of the MULTIPLY function.
  4. For rules regaring the ON SIZE ERROR clause, 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.
Back to top