SUBTRACT-CORRESPONDING

Basic form

SUBTRACT-CORRESPONDING struc1 FROM struc2.

This statement is not allowed in an ABAP Objects context. See Operations based on pairs of identically-named fields not allowed.

Effect

struc1 and struc2 are regarded as structures, that is, if they are, for example, internal tables with header lines, the statement will apply to the header lines, not the table body.
The statement looks for fields that occur with the same name in both struc1 and struc2. For each pair of identically-named fields ni, the system generates a

SUBTRACT struc1-ni FROM struc2-ni.

statement. Components that do not have a corresponding field in the other structure remain unchanged.

In a complex structure, the full names of the field pairs must be identical.

Example

DATA:  BEGIN OF PERSON,
         NAME(20)     VALUE 'Paul',
         MONEY TYPE I VALUE 5000,
       END   OF PERSON.
TYPES: BEGIN OF PURCHASE,
         PRODUCT(10),
         MONEY TYPE I,
       END   OF PURCHASE.
DATA:  PURCHASES    TYPE TABLE OF PURCHASE,
       PURCHASES_WA LIKE LINE OF PURCHASES.
PURCHASES_WA-PRODUCT = 'Table'.
PURCHASES_WA-MONEY = 100.
APPEND PURCHASES_WA TO PURCHASES.

PURCHASES_WA-PRODUCT = 'Chair'.
PURCHASES_WA-MONEY =  70.
APPEND PURCHASES_WA TO PURCHASES.

LOOP AT PURCHASES INTO PURCHASES_WA.
  SUBTRACT-CORRESPONDING PURCHASES_WA FROM PERSON.
ENDLOOP.

The value of PERSON-MONEY is now 4830. The above SUBTRACT-CORRESPONDING statement, executed twice, is the equivalent of the following statement:

SUBTRACT PURCHASES_WA-MONEY FROM PERSON-MONEY.

Note

The system performs the subtraction on all pairs of identically-named fields, not just numeric ones. The same conversions are performed as apply to the SUBTRACT.

Exceptions

Catchable Exceptions

CX_SY_ARITHMETIC_OVERFLOW

CX_SY_CONVERSION_OVERFLOW

(T P, with specified length) Runtime Error: BCD_FIELD_OVERFLOW (catchable)

Non-Catchable Exceptions

Cause: P field does not contain correct BCD

format

Runtime Error: BCD_BADDATA

Related

SUBTRACT, MOVE-CORRESPONDING, ADD-CORRESPONDING, MULTIPLY-CORRESPONDING, DIVIDE-CORRESPONDING

Additional help

Arithmetic Calculations