This is a test message to test the length of the message box.
Login
ABAP Quick RFC error handling
Created by Software-Heroes

ABAP Quick - RFC Error handling

920

How do you actually handle errors when communicating via a destination in the function module? More about this in our tip.



Calling function modules is standard in processing, especially if you use SAP's standard BAPIs. The BAPIs can usually also be called on other systems to carry out the processing there.

 

Introduction

In reviews we often see RFC calls where error handling has not been properly implemented. In many cases you will find the following implementation of the call.

CALL FUNCTION 'BAPI_USER_ACTGROUPS_ASSIGN' DESTINATION is_roles-destination
  EXPORTING
    username              = is_roles-userid
  TABLES
    activitygroups        = is_roles-activitygroups
    return                = rt_return
  EXCEPTIONS
    OTHERS                = 1.

 

Since a destination is used, it is an RFC call; in this case, the error messages are returned via the SUBRC. Apart from OTHERS, there is no other EXCEPTION when calling the function module.

 

Errors

In addition to the classic error messages from the function module, general errors can also occur in the RFC scenario:

  • Calling system does not exist or is not available
  • RFC connection not configured correctly
  • No permissions for S_RFC or S_RFCACL

 

If these errors are not caught properly, a dump occurs when the function module is called and processing cannot be completed cleanly.

 

Implementation

What does the correct implementation of the call actually look like? To do this, you have to search the documentation a bit to find the right section. In addition to OTHERS, there are two other EXCEPTIONS that the function module can set and also transfer the error message to a message variable.

DATA ld_message TYPE c LENGTH 200.

CALL FUNCTION 'BAPI_USER_ACTGROUPS_ASSIGN' DESTINATION is_roles-destination
  EXPORTING
    username              = is_roles-userid
  TABLES
    activitygroups        = is_roles-activitygroups
    return                = lt_return
  EXCEPTIONS
    system_failure        = 1 MESSAGE ld_message
    communication_failure = 2 MESSAGE ld_message
    OTHERS                = 3.

IF sy-subrc <> 0.
  " Log ld_message
ENDIF.

 

If an exception is now triggered, you will find the error message in LD_MESSAGE and can output it or log it in the log.

 

Conclusion

Handling errors when calling is not difficult, but it differs from classic error handling, which is why it is often forgotten. In the event of an error, however, it helps to exit the program cleanly and log the error.

 

Source:
SAP Documentation - CALL Function ... parameter list


Included topics:
QuickRFC Error handling
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP in Practice - Test Driven Development

Category - ABAP

How does TDD actually work in practice and are there simple examples for learning in ABAP? In this exercise we will look at the practical part.

09/24/2024

ABAP in Practice - Merge data sets

Category - ABAP

How do we merge two different data sets in ABAP, especially with regard to Modern ABAP? A practical task for this topic.

09/17/2024

ABAP in Practice - Modern ABAP

Category - ABAP

In this small task we look at existing classic ABAP source code and try to optimize it according to Modern ABAP.

08/27/2024

ABAP Quick - Performance Data Filtering

Category - ABAP

Which statement do you use in ABAP to filter internal tables and is it performant? Read more in this article.

08/13/2024

ABAP in Practice - Type Conversion

Category - ABAP

How would you perform this type conversion in ABAP? A practical example and a suggested solution.

07/16/2024