Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Obsolete Language Elements →  Obsolete Processing of Internal Data →  Obsolete Calculation Statements 

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

Other versions: 7.31 | 7.40 | 7.54

Obsolete Syntax

ADD-CORRESPONDING      struc1 TO   struc2.
SUBTRACT-CORRESPONDING struc1 FROM struc2.
MULTIPLY-CORRESPONDING struc1 BY   struc2.
DIVIDE-CORRESPONDING   struc1 BY   struc2.

Effect

These statements, forbidden in classes, add, substract, multiply, or divide structures by component. Structures must be specified for struc1 and struc2. All components of the same name in struc1 and struct2 are processed in pairs and the result is assigned to the respective component of struct2.

The names are compared, as in the statement MOVE-CORRESPONDING. For each identically named component pair comp, the statement

  • ADD struc1-comp TO struc2-comp.
  • SUBTRACT struc1-comp FROM struc2-comp.
  • MULTIPLY struc1-comp BY struc2-comp.
  • DIVIDE struc1-comp BY struc2-comp.

is executed internally, and the appropriate conversions are performed, if necessary. In complex structures, the names of the field pairs in question have to be completely identical at all hierarchical levels.


Note

These statements are error-prone because, particularly in complex structures, it is not easy to check that components of the same name have the data type and content necessary for a numeric operation.


Example

The components x and y exist in both structures and are added. After the addition, the results are in struc2-x and struc2-y.

DATA: BEGIN OF struc1, 
        x       TYPE i, 
        y TYPE i, 
        z TYPE i, 
      END OF struc1, 
      BEGIN OF struc2, 
        a      TYPE i, 
        b      TYPE i, 
        x      TYPE p LENGTH 8 DECIMALS 0, 
        y      TYPE p LENGTH 8 DECIMALS 0, 
      END OF struc2. 

... 

ADD-CORRESPONDING struc1 TO struc2. 

Exceptions

Handleable Exceptions

CX_SY_ARITHMETIC_OVERFLOW

  • Cause: Overflow in addition, type I in the additions UNTIL or FROM ... TO
    Runtime error: ADDF_INT_OVERFLOW
  • Cause: Overflow in arithmetic operation (type p)
    Runtime error: BCD_OVERFLOW
  • Cause: Integer overflow in addition
    Runtime error: COMPUTE_INT_PLUS_OVERFLOW

CX_SY_CONVERSION_OVERFLOW

  • Cause: Overflow in arithmetic operation (type p, with specified length)
    Runtime error: BCD_FIELD_OVERFLOW

CX_SY_ZERODIVIDE

  • Cause: Division by 0 (type p)
    Runtime error: BCD_ZERODIVIDE
  • Cause: Division by 0 (type f)
    Runtime error: COMPUTE_FLOAT_ZERODIVIDE
  • Cause: Division by 0 (type i)
    Runtime error: COMPUTE_INT_ZERODIVIDE

Non-Handleable Exceptions

  • Cause: p field does not contain the correct BCD format
    Runtime error: BCD_BADDATA