Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

Adds two or more operands and stores the result in one or more data

Posted By: Volker Fischer     Category: Cobol     Views: 3646

Program that Adds two or more operands and stores the result in one or more data.

Code for Adds two or more operands and stores the result in one or more data in Cobol

IDENTIFICATION DIVISION.
PROGRAM-ID. TEST_ADD.

DATA DIVISION.
WORKING-STORAGE SECTION.
77 NUM-01                   PIC 9(3)V9(2) VALUE  64.2.
77 NUM-02                   PIC 9(15)V9(2) VALUE 1234567890123.67.
77 NUM-03                   PIC 9(3)V9(2) COMP VALUE 123.45.
77 NUM-04                   PIC S9(4)V9(3) COMP VALUE  -90.6.
77 NUM-05                   PIC 9(3)V9(2) COMP VALUE   1.
77 NUM-06                   PIC 9(3)V9(2) COMP VALUE   0.02.
77 NUM-07                   PIC 9(6)V9(2) COMP VALUE 876543.67.
77 NUM-08                   PIC 9(14)V9(3) COMP VALUE 876543.67.

01 GROUP-01.
   05 N-01                  PIC 9(4)           VALUE 11.
   05 N-02                  PIC 9(5)V9(2) COMP VALUE 22.22.
   05 N-03                  PIC 9(3)V9(1)      VALUE 33.3.

01 GROUP-02.
   05 N-02                  PIC 9(5)V9(2) COMP VALUE 66.66.
   05 N-01                  PIC 9(4)           VALUE 55.
   05 N-03                  PIC 9(3)V9(1)      VALUE 77.7.

77 EDI-01                   PIC -,---,---,---,--9.999.

PROCEDURE DIVISION.
MAIN.

*   Add data-1 to data-2
    MOVE NUM-01 TO EDI-01 DISPLAY " " EDI-01
    MOVE NUM-02 TO EDI-01 DISPLAY "+" EDI-01
    ADD  NUM-01 TO NUM-02
    MOVE NUM-02 TO EDI-01 DISPLAY "=" EDI-01 DISPLAY " "

*   Add data-1 to data-2
    MOVE NUM-03 TO EDI-01 DISPLAY " " EDI-01
    MOVE NUM-04 TO EDI-01 DISPLAY "+" EDI-01
    ADD  NUM-03 TO NUM-04
    MOVE NUM-04 TO EDI-01 DISPLAY "=" EDI-01 DISPLAY " "

*   Add data-1 data-2 to data-3
    MOVE NUM-05 TO EDI-01 DISPLAY " " EDI-01
    MOVE NUM-06 TO EDI-01 DISPLAY "+" EDI-01
    MOVE NUM-07 TO EDI-01 DISPLAY "+" EDI-01
    ADD  NUM-05 NUM-06 TO NUM-07
    MOVE NUM-07 TO EDI-01 DISPLAY "=" EDI-01 DISPLAY " "

*   Add data-1 + data2 + literal giving data-3
    MOVE NUM-07 TO EDI-01 DISPLAY " " EDI-01
    MOVE NUM-01 TO EDI-01 DISPLAY "+" EDI-01
    MOVE 50.2134 TO EDI-01 DISPLAY "+" EDI-01
    ADD  NUM-07 NUM-01 50.2134 GIVING NUM-08
    MOVE NUM-08 TO EDI-01 DISPLAY "=" EDI-01 DISPLAY " "

*   Add corr
    MOVE N-01 OF GROUP-01 TO EDI-01 DISPLAY " " EDI-01 WITH NO ADVANCING
    MOVE N-02 OF GROUP-01 TO EDI-01 DISPLAY " " EDI-01 WITH NO ADVANCING
    MOVE N-03 OF GROUP-01 TO EDI-01 DISPLAY " " EDI-01
    MOVE N-01 OF GROUP-02 TO EDI-01 DISPLAY "+" EDI-01 WITH NO ADVANCING
    MOVE N-02 OF GROUP-02 TO EDI-01 DISPLAY " " EDI-01 WITH NO ADVANCING
    MOVE N-03 OF GROUP-02 TO EDI-01 DISPLAY " " EDI-01
    ADD CORRESPONDING GROUP-01 TO GROUP-02
    MOVE N-01 OF GROUP-02 TO EDI-01 DISPLAY "=" EDI-01 WITH NO ADVANCING
    MOVE N-02 OF GROUP-02 TO EDI-01 DISPLAY " " EDI-01 WITH NO ADVANCING
    MOVE N-03 OF GROUP-02 TO EDI-01 DISPLAY " " EDI-01


    STOP RUN
    .
* =================================================================

* The result is:

*                 64.200
* +1,234,567,890,123.670
* =1,234,567,890,187.870
*
*                123.450
* +              -90.600
* =               32.850
*
*                  1.000
* +                0.020
* +          876,543.670
* =          876,544.690
*
*            876,544.690
* +               64.200
* +               50.213
* =          876,620.903
*
*                 11.000                22.220                33.300
* +               55.000                66.660                77.700
* =               66.000                88.880               111.000
  
Share: 



Volker Fischer
Volker Fischer author of Adds two or more operands and stores the result in one or more data is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!