SAP DIVISION ZERO - Guide
Get Example source ABAP code based on a different SAP table
Division by Zero
ABAP_BACKGROUND
Division by zero is forbidden in all recognized programming languages and raises an exception. This is also the case in ABAP, but with the difference that the exception
ABAP_RULE
Do not exploit the fact that ABAP allows division by zero if the dividend itself is zero.
ABAP_DETAILS
This ABAP behavior is arbitrary and does not produce the result expected by the user. Therefore, it should not be exploited. Instead, set preconditions that avoid division by zero or the corresponding exception is to be triggered explicitly for the case 0/0.
Example ABAP Coding
The following source code always raises an exception when the divisor has the value 0.
result = dividend / divisor.
ELSE.
RAISE EXCEPTION TYPE cx_sy_zerodivide.
ENDIF.>
ABAP_EXAMPLE_END