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: 

Getting exception short text using FM name and sy-subrc value

Former Member
0 Kudos

Dear All,

I am struck up with I guess a basic issue in exception handling.

Is there a simple way to obtain the exception short text(maintained in Table FUNCT) after a function module call.

I would prefer not to use any CASE statements after the FM call.

ex : If my FM call returns a sy-subrc 6, I would need to get the corresponding short text for the exception "No Payroll Result Found".

If I can just pass the function module name and the sy-subrc value to some FM, 

could I possible get the exception text?

   CALL FUNCTION 'PYXX_READ_PAYROLL_RESULT'
    EXPORTING
*     CLUSTERID                    =
      employeenumber               = peras-pernr
      sequencenumber               = gs_rgdir-seqnr
      read_only_international      = 'X'
*     CHECK_READ_AUTHORITY         = 'X'
    CHANGING
      payroll_result               = gt_result
    EXCEPTIONS
      illegal_isocode_or_clusterid = 1
      error_generating_import      = 2
      import_mismatch_error        = 3
      subpool_dir_full             = 4
      no_read_authority            = 5
      no_record_found              = 6
      versions_do_not_match        = 7
      error_reading_archive        = 8
      error_reading_relid          = 9
      OTHERS                       = 10.

Thanks & Regards,

Rijuraj

3 REPLIES 3

tkaess
Participant
0 Kudos

Hello,

I think, it isn’t possible.

Reason 1:

The caller must handle the exceptions.

Reason 2:

The order and the numbers of exception statements is free…

For  example:

Exceptions

ex1      =          1

ex2      =          2

ex3      =          3

Exceptions

ex1      =          20

ex2      =          90

Exceptions

ex2      =          10

ex1      =          20

Reason 3:

SAP works with a message table (bapiret).

Reason 4:

You don’t need a message by an exception.

In the new world – in OO – we have other possibilities. The handling with exception classes and TRY/ENDTRY it’s better.

Best regards

Thomas

kesavadas_thekkillath
Active Contributor
0 Kudos

Read SAP help on "Message - message_options" and the "into text" option. When you use the fm through pattern , the message statement appears in between the sy-subrc check after the fm call. Just uncomment it and use "into" statement to capture the message.

che_eky
Active Contributor
0 Kudos

Take a look at the following function modules:

SWO_QUERY_FUNCTION_EXCEPTION

SWO_QUERY_FUNCTION_EXCEPTIONS

The first module will return the exception text if you give it the function module and exception. Unfortunately you have to pass the "name" of the exception and not the value. So you would have to pass the exception as "no_record_found" and not 6 (sy-subrc). This is because internally the exceptions are keyed on name (NO_RECORD_FOUND, ERROR_READING_RELID, etc) and not on there position 6, 9, etc. The position of an exception can be redefined when you call the function, for example NO_RECORD_FOUND = 1.

What you could do is use the second function module SWO_QUERY_FUNCTION_EXCEPTIONS to determine all exceptions for a function. Then read the corresponding exception using your return code and call the first function module to get the actual text. This assumes you use the default exception list returned when coding the function module call, using all exceptions of the function module.