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

how to capture error message from standard function module

Former Member
0 Likes
21,757

Dear friends

when i  execute standard function module in finance , i am getting error message , pls check the below screen shot,

how to capture the below error message so that i have display in my webdynpro component

Thanks

Vijaya

10 REPLIES 10
Read only

sivaganesh_krishnan
Contributor
8,657

hi ,

Sap has provided option to capture exceptions while error occures in a FM .

Use this

DATA mtext TYPE string.
      CALL FUNCTION ... EXCEPTIONS error_message = 4.
      IF sy-subrc = 4.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                INTO mtext
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.


Regards,

Sivaganesh

Read only

0 Likes
8,657

Hi Vijaya.

The solution given by Sivaganesh is perfect for all MESSAGEs without RAISING option.

If the MESSAGE has a RAISING option, you have to catch this EXCEPTION explicitely in your fm call

Regards,

Klaus

Read only

Former Member
0 Likes
8,657

Please explain in detail how you are trigerring the FM.

By double clicking on the message you can get the message no. and ID.

Read only

Former Member
0 Likes
8,657

lx_return TYPE BAPIRET2.


call FM.

IF sy-subrc NE 0.

           MESSAGE ID sy-msgid

              TYPE sy-msgty

            NUMBER sy-msgno

              WITH sy-msgv1

                   sy-msgv2

                   sy-msgv3

                   sy-msgv4

              INTO lx_return-message.

           lx_return-type = sy-msgty.

ENDIF.

Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
8,657

Hi Vijaya

Can you please provide the details of the FM which you are using along message id and message class detail


Nabheet

Read only

0 Likes
8,657

Hi Nabheet,

You can use the below FM for capturing the error message.

data: ls_msg TYPE bapiret2,

CALL FUNCTION '/SNP/DW01_UTILS_FORMAT_MESSAGE'
             EXPORTING
               iv_id     = sy-msgid
               iv_number = sy-msgno
               iv_type   = sy-msgty
               iv_p1     = sy-msgv1
               iv_p2     = sy-msgv2
               iv_p3     = sy-msgv3
               iv_p4     = sy-msgv4
             IMPORTING
               ew_result = ls_msg.


Regards,

Mohammed

Read only

Former Member
0 Likes
8,657

Hi Vijaya,

in most cases there is a table T_RETURN as an output parameter in the function module which is BAPIRET2 struture where you can retrieve the error message 

regards

Read only

Former Member
0 Likes
8,657

Hi Vijaya,

You can use the below FM for capturing the error message.

data: ls_msg TYPE bapiret2,

CALL FUNCTION '/SNP/DW01_UTILS_FORMAT_MESSAGE'
             EXPORTING
               iv_id     = sy-msgid
               iv_number = sy-msgno
               iv_type   = sy-msgty
               iv_p1     = sy-msgv1
               iv_p2     = sy-msgv2
               iv_p3     = sy-msgv3
               iv_p4     = sy-msgv4
             IMPORTING
               ew_result = ls_msg.


Regards,

Mohammed

Read only

Former Member
0 Likes
8,657


Hello,

User error_message after FM. this is capture all messagae (RAISING  or without)

CALL FUNCTION 'ZTEST'

IMPORT

..........

EXCEPTIONS

error_message = 01

IF SY-SUBRC <>0.

" carry out exception handling

ENDIF.

Details fo error_message are explained in below doc

http://help.sap.com/abapdocu_70/en/ABAPCALL_FUNCTION_PARAMETER.htm

There are few threads also in SCN for the same. you can check it incase of doubt

Cheers,

Nag

Read only

ThangaPrakash
Active Contributor
0 Likes
8,657

Hello Vijaya,

Incase of BAPI's they have a return table parameter T_RETURN. Just read that return table to get the error message.

Incase of normal function modules, there will be exceptions raised for the message used inside the function module. Just read the sy-subrc after the FM and based on the sy-subrc value find the respective exception raised.

May be you can try like this, whenever the message is raised it will be stored in the system variable.

CALL FM.

check for the system variables.

sy-msgid = Message ID of the latest message raised.


sy-msgno = message number of the latest message raised.


sy-msgty = message type of the latest message raised.


sy-msgv1 = variable1 of the latest message raised.


sy-msgv2 = variable2 of the latest message raised.


sy-msgv3 = variable3 of the latest message raised.


sy-msgv4 = variable4 of the latest message raised.

Regards,

TP