Application Development 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: 

Extract the message from an exception?

jrgkraus
Active Contributor
0 Kudos

Let's say, I have an exception object with a non-dynamic T100 interface (message id and type is assigned in the coding). Now, I need to get the whole message in order to pass it to a BAPIRET2 structure. In the T100 interface, I have only the names of the attributes that populate MSGV1, MSGV2 ... in components called ATTR1, ATTR2....

To get the values for MSGV.. I have to do a series of dynamical assigns.

I am wondering if there is any standard tool for this? It seems to be a common task, but I did not find anything.

1 ACCEPTED SOLUTION

Tomas_Buryanek
Active Contributor
0 Kudos

Are not variables in sy-msg* variables?

If not then you can get them there by triggering MESSAGE from exception object.
It is nice to prepare some utility method for that. Here is example without method:

TRY.
  "...
CATCH zcx_exception INTO DATA(lo_exception).
  
  MESSAGE lo_exception INTO ls_bapiret2-message.
  ls_bapiret2-message_v1 = sy-msgv1.
  "...  

ENDTRY.

EDIT: ah sorry, it seems that MESSAGE oref INTO is not allowed 😞
EDIT2: You can try CL_MESSAGE_HELPER method SET_MSG_VARS_FOR_IF_T100_MSG that fills sy-msgv* and other fields 🙂

-- Tomas --
2 REPLIES 2

Tomas_Buryanek
Active Contributor
0 Kudos

Are not variables in sy-msg* variables?

If not then you can get them there by triggering MESSAGE from exception object.
It is nice to prepare some utility method for that. Here is example without method:

TRY.
  "...
CATCH zcx_exception INTO DATA(lo_exception).
  
  MESSAGE lo_exception INTO ls_bapiret2-message.
  ls_bapiret2-message_v1 = sy-msgv1.
  "...  

ENDTRY.

EDIT: ah sorry, it seems that MESSAGE oref INTO is not allowed 😞
EDIT2: You can try CL_MESSAGE_HELPER method SET_MSG_VARS_FOR_IF_T100_MSG that fills sy-msgv* and other fields 🙂

-- Tomas --

CL_MESSAGE_HELPER was exactly what I looked for. Thank you so much.