ā2015 Dec 15 8:55 AM
As known, you can catch this error by using 'cx_sy_arithmetic_error'.
My question is, is it possible to do it without try catch.
I have tried, if you just use sy-subrc, it would cause a dump.
ā2015 Dec 15 9:19 AM
Hi Ming
So why do you want to bypass this standard code?
Regards
Arden
ā2015 Dec 15 9:25 AM
Actually, I am telling a develop who came from Java that sy-subrc/raise exception is better than try catch in easily reading.
But there might be some places where sy-subrc cannot be used like dividing zero.
ā2015 Dec 15 9:29 AM
Hi Ming,
Otherwise you can place a condition checking whether divisor variable is holding value zero or not. If divisor value is not equal to 0, then only do the division.
Sample:
IF LV_DIVISOR <> 0.
LV_QUOT = LV_DIVIDEND / LV_DIVISOR.
ENDIF.
Thanks and Regards,
Vijay
ā2015 Dec 15 5:11 PM
I would say that this is bad advice for you to give.... TRY-CATCH is the best approach for many scenarios, and with the increased use of exception classes (the recommended exception handling approach for class based development) it becomes more and more common.
Jim
ā2015 Dec 16 1:47 AM
I know that try catch is becoming common and it's has more function because it's class-based.
However, since most of methods have exception, especially if you want the logic as strict as possible. Then you will find you code are full of TRY & CATCH. It's not convenience to code and read. Compare this:
In Java:
try
{
call method;
}
catch (xxxException)
{
//handl exception
}
In ABAP
call FM or method.
case sy-subrc.
endcase.
I preffer the ABAP way.
ā2015 Dec 15 4:57 PM
Hi Ming,
View the code.
DATA lv_val TYPE P.
CATCH SYSTEM-EXCEPTIONS conversion_errors = 1
arithmetic_errors = 5.
lv_val = 100 / 0.
ENDCATCH.
Hope it helpful.
Regards,
Venkat.
ā2015 Dec 15 5:11 PM
ā2015 Dec 15 5:22 PM
ā2015 Dec 16 1:48 AM
ā2015 Dec 16 2:13 PM
And you just ignore the message about obsolete syntax ?
Well.......................... I better say nothing.
ā2015 Dec 16 2:26 PM
ā2015 Dec 17 1:45 AM
I saw it. I am not saying I will use this.
I am just looking for the way that traditional ABAP does this.
Anyway, thank you for you remind.