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

Capture error message in RFC

Former Member
0 Likes
1,719

Hi,

I have created a custom RFC which calls a standard transaction internally using SUBMIT statement.

The problem I face is that I am not able to capture the message when the standard transaction ends in error, as the control does not come back to the RFC.

Please let me know how can I capture error messages in such case. The RFC is called from another system and I need to pass the error message to the calling system.

Regards,

Dawood

Hi,

I have created a custom RFC which calls a standard transaction internally using SUBMIT statement.

The problem I face is that I am not able to capture the message when the standard transaction ends in error, as the control does not come back to the RFC.

Please let me know how can I capture error messages in such case. The RFC is called from another system and I need to pass the error message to the calling system.

Regards,

Dawood

5 REPLIES 5
Read only

former_member213851
Active Contributor
0 Likes
1,123

Hi Dawood,

After executing, CALL TRANSACTION stmt, depending upon the SY-SUBRC value dispaly the Error Message .

Read only

0 Likes
1,123

I need to use SUBMIT pgm as I am also passing the selection criteria.

Read only

0 Likes
1,123

Are you getting correct data in SYST structure?

I think you should generally get the error message in sy-msgid and sy-msgno etc.

Populate those messages in structure BAPIRET2 and send it back to the system.

Read only

0 Likes
1,123

Hi Dawood,

Please try using the FM FORMAT_MESSAGE to get all the messages generated at Run-time.

Below is the  Demo code:

CALL TRANSACTION  'MM01'  USING BDCDATA MODE  'A'  UPDATE  'S'.

If sy-subrc ne 0.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

* ID              = SY-MSGID

LANG            = 'EN'

* NO              = SY-MSGNO

* V1              = SY-MSGV1

* V2              = SY-MSGV2

* V3              = SY-MSGV3

* V4              = SY-MSGV4

IMPORTING

MSG             = TEXT

* EXCEPTIONS

* NOT_FOUND       = 1

* OTHERS          = 2

          .

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CONCATENATE INDEX TEXT INTO TEXT SEPARATED BY ' . ' .

Thus you can capture Message No and corresponding  Text  and use it as Exceptions as per requirement.

Best Regards,

Sachin

Read only

0 Likes
1,123

This cannot be done using the SUBMIT statement, because the moment SUBMIT is called the control is transferred to the called program. If an error is raised in this program, the processing stops and the control does not return back to the main program (your RFC) for processing.

In case of RFC it is always advised not to raise any error messages, instead pass the errors back as parameters to the RFCs (like most BAPI calls have the BAPIRETURN table to capture errors).

The only option that I see is to encapsulate the logic of the program that you are calling in your RFC and instead of issuing error messages, capture them in a parameter table returned by the RFC.

-Puneet