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: 

How to pass FM Exceptions as message

Khaled_Elghali
SAP Champion
SAP Champion
0 Kudos
4,274

Hi Experts,

Is there a trick to pass the exception message (in case of failure) of the function module to an abap variable ?

e.g. for the following FM there are 17 specified exceptions:

If an exception with ID INVALID_REQUEST is thrown, how can I store the text message in red in an abap string (exception_str) ?

Here is how I intend to use it:

IF sy-subrc <> 0.
MESSAGE exception_str TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.

Any help will be appreciated.
Khaled

1 ACCEPTED SOLUTION

harald_lesche-holzbecher
Product and Topic Expert
Product and Topic Expert
3,070

sy-msg* fields are already set by FM.

So you may simply output the message using sy-msg* fields:

MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

3 REPLIES 3

juan_suros
Contributor
3,070

The exception texts for function modules are stored in the data dictionary in table FUPARAREF

DoanManhQuynh
Active Contributor
3,070

There are 2 type of message from function module ( I think):

One with raising exception and one without raising.

So for message with raising exception, you already have exception number and you check sy-subrc to get it. the message ID, number...is stored in system: SY-MSGID, SY-MSGTY...which if you call fm through pattern button, it will generate the code for you.

With message without raising exception, you have to add ERROR_MESSAGE to exception part of function module and do the same as above.

harald_lesche-holzbecher
Product and Topic Expert
Product and Topic Expert
3,071

sy-msg* fields are already set by FM.

So you may simply output the message using sy-msg* fields:

MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.