Skip to Content
0
Mar 10, 2015 at 06:49 AM

easy way to get the exception text returned by FM (without case/IF)

1613 Views

Hi All,

it is basic thing, but want to generalize my code, so asking,

DATA lv_str TYPE string.

DATA: lt_p1001 TYPE TABLE OF p1001.

CALL FUNCTION 'RH_READ_INFTY'

EXPORTING

authority = 'DISP'

with_stru_auth = 'X'

plvar = '01'

otype = 'S'

objid = '1234678'

infty = '1001'

istat = '1'

TABLES

innnn = lt_p1001

EXCEPTIONS

all_infty_with_subty = 1

nothing_found = 2

no_objects = 3

wrong_condition = 4

wrong_parameters = 5

OTHERS = 6.

I want to get the codes e.g all_infty_with_subty or nothing_found, not just sy-subrc 1 or 2 at runtime, so that i can pass the code

Currently i am getting with case statements like below.

IF sy-subrc <> 0.

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

* INTO mtext WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

CASE sy-subrc.

WHEN 1.

lv_str = 'all_infty_with_subty'.

WHEN 2.

lv_str = 'nothing_found'.

WHEN 3.

lv_str = 'no_objects'.

WHEN 4.

lv_str = 'wrong_condition'.

WHEN 5.

lv_str = 'wrong_parameters'.

WHEN 6.

lv_str = 'others'.

WHEN OTHERS.

ENDCASE.

ENDIF.

In our project, there are lot of FMs, which return exceptions, but i am looking for generic way to get the exception code text based on sy-subrc.

i tried using the FMs FORMAT_MESSAGE and BAPI_MESSAGE_GETDETAIL, but they are not giving the exception code text.

thanks in advance.

Madhu_1980