Add Verb in COBOL

Add Verb

Add verb is used to add two or more numbers. The result is stored in the destination operand.

Syntax

ADD A B TO C D                                  ---- Syntax 1

ADD B C D  TO  E GIVING F                 ---- Syntax 2

ADD CORR WS-GR1 TO WS-GR2         ---- Syntax 3


In syntax 1, A, B, C  are added and the result is stored in C. i.e C=A+B+C and A, B, D are added and result is stored in D.
i.e D = A+B+D

In syntax 2, B, C, D & E are added and the result is stored in E.
i.e E = B+C+D+E

In syntax 3, sub grouped item in WS-GR1 and WS-GR2 are added and the result is stored WS-GR2.

Example : Demonstration of Add verb

IDENTIFICATION DIVISION.
PROGRAM-ID. AV.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-N1 PIC 9(2) VALUE 15.
   01 WS-N2 PIC 9(2) VALUE 10.
   01 WS-N3 PIC 9(2) VALUE 15.
   01 WS-N4 PIC 9(2) VALUE 20.
   01 WS-NA PIC 9(2) VALUE 5.
   01 WS-NB PIC 9(2) VALUE 7.
   01 WS-NC PIC 9(3) VALUE 12.
   01 WS-ND PIC 9(2) VALUE 10.
   01 WS-NE PIC 9(3) VALUE 10.

PROCEDURE DIVISION.
   ADD WS-N1 WS-N2 TO WS-N3 WS-N4.
   ADD WS-NA WS-NB WS-NC TO WS-ND GIVING WS-NE.
   DISPLAY "WS-N1     : " WS-N1
   DISPLAY "WS-N2     : " WS-N2
   DISPLAY "WS-N3     : " WS-N3
   DISPLAY "WS-N4     : " WS-N4
   DISPLAY "WS-NA     : " WS-NA
   DISPLAY "WS-NB     : " WS-NB
   DISPLAY "WS-NC     : " WS-NC
   DISPLAY "WS-ND     : " WS-ND
   DISPLAY "WS-NE     : " WS-NE

STOP RUN.


Output:
WS-N1     : 15
WS-N2     : 10
WS-N3     : 40
WS-N4     : 45
WS-NA     : 05
WS-NB     : 07
WS-NC     : 012
WS-ND     : 10
WS-NE     : 034