09-07-2006 9:16 AM
Hi ABAP Experts:)
I am expecting problems with TRY..ENDTRY block. What I need is when any kind of error occurs within a TRY..ENDTRY block then program should show a message and stop executing the program. I wrote the following code using class-based exceptions (CX_ROOT, that is defined as a handler for all exceptions):
TRY.
SELECT COUNT(*)
INTO lv_field_count
FROM (lv_from)
WHERE (lt_where_1).
CATCH CX_ROOT.
MESSAGE e003.
ENDTRY.
But practically, it doesn't catch all possible errors (for example, runtime error CONVT_NO_NUMBER).
I tried to use old-fashioned SYSTEM-EXCEPTIONS for specific errors, but it didn't work too (it shows a runtime error and ignores my MESSAGE e003):
CATCH SYSTEM-EXCEPTIONS CONVERSION_ERRORS = 1.
SELECT COUNT(*)
INTO lv_field_count
FROM (lv_from)
WHERE (lt_where_1).
ENDCATCH.
IF SY-SUBRC = 1.
MESSAGE e003.
ENDIF.
Currently I am using SAP GUI 6.40 version. I searched for help on this topic, and found, that:
"Starting with Release 6.10, exceptions are generally handled based on the class. Therefore, each catchable runtime error is assigned a predefined exception class. This allows you to catch this error like all catchable exceptions between the statements TRY..ENDTRY using the statement CATCH. This is the preferred method."
So, it looks like my code should work. Any help is appreciated!
Regards,
Santosh.
09-07-2006 10:46 AM
hi,
Your objective looks perfectly fine but lets do some fine tuning :
data : o_ref type ref to cx_root,
msg type string.
TRY.
SELECT COUNT(*)
INTO lv_field_count
FROM (lv_from)
WHERE (lt_where_1).
CATCH CX_ROOT into o_ref.
ENDTRY.
if SY-SUBRC <> 0.
Msg = O_REF->GET_TEXT( ).
write msg.
endif.
Reward if helpful.
Rgds
09-07-2006 2:05 PM
09-08-2006 5:50 AM