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?

Former Member
0 Likes
645

How to capture error message like below in to the string?

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

Regards

Ronny

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
603

Hello Ronny,

try

Data:

wa_error(150) type C.

          • Call Function/BAPI

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = sy-msgid

no = sy-msgno

v1 = sy-msgv1

v2 = sy-msgv2

v3 = sy-msgv3

v4 = sy-msgv4

IMPORTING

msg = wa_err

EXCEPTIONS

not_found.

If wa_err is not initial.

Write:/ 'This error occurred: ', wa_err.

endif.

Regards,

C

3 REPLIES 3
Read only

Former Member
0 Likes
604

Hello Ronny,

try

Data:

wa_error(150) type C.

          • Call Function/BAPI

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = sy-msgid

no = sy-msgno

v1 = sy-msgv1

v2 = sy-msgv2

v3 = sy-msgv3

v4 = sy-msgv4

IMPORTING

msg = wa_err

EXCEPTIONS

not_found.

If wa_err is not initial.

Write:/ 'This error occurred: ', wa_err.

endif.

Regards,

C

Read only

ThomasZloch
Active Contributor
0 Likes
603

even easier:

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno INTO lf_string

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

Thomas

Read only

former_member585060
Active Contributor
0 Likes
603

call transaction 'XK01' using i_bdcdata

mode 'N'

update 'S'

messages into i_bdcmsgcoll.

if sy-subrc <> 0.

perform get_error.

write:/ itab , v_text.

endif.

*****************************************

*Form

*****************************************

form get_error.

loop at i_bdcmsgcoll.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = i_bdcmsgcoll-MSGID

LANG = sy-langu

NO = i_bdcmsgcoll-MSGNr

V1 = i_bdcmsgcoll-MSGV1

  • V2 = SY-MSGV2

  • V3 = SY-MSGV3

  • V4 = SY-MSGV4

IMPORTING

MSG = v_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.

endloop.

endform. " get_error

Edited by: Bala Krishna on Sep 9, 2008 7:50 PM