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

Exception 'error_message' in ABAP Objects

manfred_oster
Explorer
0 Likes
2,610

I've got a heterogeneous scenario with new program parts in ABAP objects and older parts in classical ABAP.

In the older parts some R/3 standard functions are called which dump dialog messages which are not allowed at that state of the program flow ('on commit').

The simple solution in classical ABAP was to use standard exception 'error_message' in the top level 'call function' statement thus catch all dialog messages in lower levels.

I am looking for an analog solution in object oriented ABAP. But exception 'error_message' is not allowed with 'call method'. It cannot be defined statically in the methods declaration. And the system exception caused by the dialog error message is not included in the set of catchable system errors.

I would be grateful for any hints concerning this problem.

8 REPLIES 8
Read only

Former Member
0 Likes
1,928

Please see excellent doc on new exception handling in abap objects, with also detailed description about interaction between 'classical' error handling and abap objects:

'A Programmer's guide to the New Exception Handling Concept in ABAP' available on SDN.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/f86c9290-0201-0010-7a93-dda...

regards,

Joris.

Read only

0 Likes
1,928

Thanks for your answer. But unfortunately this document is incorrect exactly in the detail concerning my problem.

According to the authors it is possible to use "error_message" with call method (p. 44, last sentence: "If the message is of type "E" or "A" it can be caught directly by calling methods and function modules using the EXCEPTION clause and the special (classical) exception name error_message.").

But that is not true at least not in release 6.20. Syntax check says that the declaration for that exception is missing. Maybe there is a certain trick that I didn't find out.

Read only

0 Likes
1,928

Hi

Excuse me! But I didn't want to sent you my answer.

Anyway:

CLASS lcl_my_class DEFINITION.

PUBLIC SECTION.

METHODS my_method

EXPORTING

EXCEPTION TYPE CHAR1

EXCEPTIONS error_messages.

ENDCLASS. "LCL_MY_CLASS DEFINITION

CLASS lcl_my_class IMPLEMENTATION.

METHOD my_method.

IF EXCEPTION = 'X'.

MESSAGE e208(00) WITH 'Message error'

RAISING error_messages.

ELSE.

MESSAGE I208(00) WITH 'OK!'.

ENDIF.

ENDMETHOD. "MY_METHOD

ENDCLASS. "LCL_MY_CLASS IMPLEMENTATION

So you did want to do a call like this:

CALL METHOD lcl_my_class=>my_method

EXCEPTIONS

error_messages = 1

error_message = 2

OTHERS = 3.

No! you can't do it, but you try to insert your call in fm where you use ERROR_MESSAGE addition. I think you can do it if your methods are std.

Max

Message was edited by: max bianchi

Read only

0 Likes
1,928

I have looked at the help of the 'call method' statement, and unfortunately it says the following:

Notes:

As with function modules, you can catch the exception OTHERS predefined by the system to handle various user-defined exceptions simultaneously. Specifying the exception ERROR_MESSAGE is, however, not supported for method calls.

I imagine that you are calling some standard methods, so you can not change the way the messages are triggered, so you can not raise an other exception in the method itself.

Message.. raising...

What you can try to do, is to encapsulate the method call in a function 'Z_CALL_METHOD_...' and call that function with exception error_message. I have not tried this, but might be a workaround to still use the methods you want to use.

Joris.

Read only

0 Likes
1,928

Thanks Joris for the last suggestion.

I had that already in mind as my last straw to clutch at.

But what is the benefit of ABAP Objects if I have to fall back to classical ABAP because the new technologie is less powerful? So I hope there is another solution.

Read only

0 Likes
1,928

Hello,

In the meantime we're 5 years further, anything changed in that time that allows now error_message in ABAP objects?

Jeroen.

Read only

Former Member
0 Likes
1,928

Hi please see at

http://www.sap-press.com/downloads/h958_preview.pdf

for more info on exception handling in abap objects.

Read only

Former Member
0 Likes
1,928