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: 

get exception text using subrc and function module name

0 Kudos

hi guru's,

how to fetch exception short text using the sy-subrc and fucntional module name.

example :

CALL FUNCTION 'EQUIPMENT_LOCK'

           EXPORTING

             equi_no        = wa_equi-equnr

           EXCEPTIONS

             equi_not_found     = 1

             lock_failure           = 2

             OTHERS              = 3.


if i get the subrc = 2 i want to get the text lock_failure in an variable .


please help.


thanks.

3 REPLIES 3

Former Member
0 Kudos

Try the below code.

data l_message  type string.

CALL FUNCTION 'EQUIPMENT_LOCK'

           EXPORTING

             equi_no        = wa_equi-equnr

           EXCEPTIONS

             equi_not_found     = 1

             lock_failure           = 2

             OTHERS              = 3.


if sy-subrc <> 0.

    call function 'FORMAT_MESSAGE'

      exporting

        id        =  sy-msgid

        lang      = sy-langu

        no        = sy-msgno

        v1        =  sy-msgv1

        v2        =  sy-msgv2

        v3        =  sy-msgv3

        v4        =  sy-msgv4

      importing

        msg       = l_message

      exceptions

        not_found = 1

        others    = 2.

endif.

you will get the message in l_message.

raymond_giuseppi
Active Contributor
0 Kudos

Use FM FUNCTION_IMPORT_INTERFACE or read data from tables FUPARAREF and FUNCT.

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

Regards,

Raymond

Former Member
0 Kudos

Hello,

You can use

IF SY-SUBRC NE 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO      WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4

ENDIF.

OR populate the text accordingly like, CASE sy-subrc. WHEN 1.     v_error = 'EQUI_NOT_FOUND'. WHEN 2.     v_error = 'LOCK_FAILURE'. ENDCASE. Regards, Syed