Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem with TRY..ENDTRY block

Former Member
0 Likes
676

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.

3 REPLIES 3
Read only

Former Member
0 Likes
474

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

Read only

0 Likes
474

Thanks Zapper

Regards,

Santosh.

Read only

Former Member
0 Likes
474

Hi,

Was my thread useful enough to solve ur problem??

Rgds