Capture error messages for function modules without exceptions
At
times we see function modules without any exceptions but still there is
an error message being thrown inside the function module if any piece
of code fails. If this situation happens then the program terminates at
that point. In this case there is no SY-SUBRC other than 0.
To solve this, in the program where you have written your code for the FM, include the following lines of code.
EXCEPTIONS
error_message = 99.
By
doing this you will ensure that whenever there is any error thrown by
the function module, SY-SUBRC is set as 99 and you can then capture the
message in system fields i.e. SY-MSGID, SY-MSGTY, SY-MSGNO, SY-MSGV1,
SY-MSGV2, SY-MSGV3, SY-MSGV4, and SY-MSGV5.
SAMPLE CODE:
CALL FUNCTION 'RV_CUSTOMER_MATERIAL_UPDATE'
TABLES
xknmt_tab = lt_xknmt
yknmt_tab = lt_ykmt
tcatalog_tab = lt_cat
EXCEPTIONS
error_message = 99.
IF sy-subrc <> 0.TABLES
xknmt_tab = lt_xknmt
yknmt_tab = lt_ykmt
tcatalog_tab = lt_cat
EXCEPTIONS
error_message = 99.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
The above logic is taken from the link http://sapabapbysrini.blogspot.com/2012/07/capture-error-messages-for-function.html
No comments:
Post a Comment