The statements ADD and ADD-CORRESPONDING are used for the addition of fields and store the result in a field variable. Here is the syntax and usage of these two statement keywords.
ADD statement Keyword
This statement is sued for adding two single fields.
See the different syntax variations of ADD statement
- ADD <x> TO <y>.
- ADD <x1> THEN <x2> UNTIL <xz> GIVING <y>.
- ADD <x1> THEN <x2> UNTIL <xz> ACCORDING TO <sel> GIVING <m>.
- ADD <x1> THEN <x2> UNTIL <xz> TO <m>.
- ADD <x1> FROM <m1> TO <mz> GIVING <m>.
ADD <x> TO <y>.
It same as y = x + y
ADD <x1> THEN <x2> UNTIL <xz> GIVING <y>.
x1, x2, x3 …. Xz is a sequence of numbers with a specified interval like 1, 3, 5, 7, … 55.
If we want to get the sum of these sequences we can use ADD 1 THEN 3 UNTIL 55 GIVING <y>. Now the variable y will be stored the sum value.
ADD-CORRESPONDING statement keyword
This statement is used for adding the sub fields of structures (remember ADD statement is used for single fields).
ADD-CORRESPONDING <structure1> TO <structure2>.
The sub fields in these two structures with the same name will be added together and stored in the structure2.
The main runtime errors for these two statements are
Also Read : View Other ABAP Keywords & Syntax -> ABAP Transaction codes