SAP ADD-CORRESPONDING ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID ADD-CORRESPONDING
• ADD-CORRESPONDING ABAP Statement
• TO ADD-CORRESPONDING (obsolete)
• SUBTRACT-CORRESPONDING ABAP Statement
• FROM SUBTRACT-CORRESPONDING (obsolete)
• MULTIPLY-CORRESPONDING ABAP Statement
• BY MULTIPLY-CORRESPONDING (obsolete)
• DIVIDE-CORRESPONDING ABAP Statement
• BY DIVIDE-CORRESPONDING (obsolete)

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

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

What does it do?
These statements, which are forbidden in classes, add, subtract, multiply, or divide structures by component. Structures must be specified for struc1 and struc2 . All identically named components 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 must be completely identical at all hierarchical levels.



Latest notes:

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



Example ABAP Coding

The components x and y occur in both structures and are added. After the addition, the results are in struc2-x and struc2-y.
ABEXA 00002
ABAP_EXAMPLE_END



Runtime Exceptions



Catchable Exceptions
CX_SY_ARITHMETIC_OVERFLOW
Reason for error:
Overflow in addition, type I in the additions UNTIL or FROM ... TO
Runtime error:
ADDF_INT_OVERFLOW
Reason for error:
Overflow in arithmetic operation (type p)
Runtime error:
BCD_OVERFLOW
Reason for error:
Integer overflow in addition
Runtime error:
COMPUTE_INT_PLUS_OVERFLOW
CX_SY_CONVERSION_OVERFLOW
Reason for error:
Overflow in arithmetic operation (type p, with specified length)
Runtime error:
BCD_FIELD_OVERFLOW
CX_SY_ZERODIVIDE
Reason for error:
Division by 0 (type p)
Runtime error:
BCD_ZERODIVIDE
Reason for error:
Division by 0 (type f)
Runtime error:
COMPUTE_FLOAT_ZERODIVIDE
Reason for error:
Division by 0 (type i)
Runtime error:
COMPUTE_INT_ZERODIVIDE

Non-catchable Exceptions
Reason for error:
p field does not contain the correct <(>BCD<)> format
Runtime error:
BCD_BADDATA
ABAP_NONCAT_END

Return to menu