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

485

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 Quick - CLEAR right

Category - ABAP

Delete correctly? In this article we want to take a look at when it makes sense to delete and how you can do it effectively.

05/12/2023

ABAP Quick - Performance chained statements

Category - ABAP

Let's take a look at the performance when creating chained statements with DATA and FIELD-SYMBOL. Which variant will be ahead in terms of performance?

04/28/2023

ABAP - ALV still relevant in 2022?

Category - ABAP

Today the joking question, do we still need reports that generate ALV outputs in 2022? In this article, we want to look into this question.

07/01/2022

ABAP in Change

Category - ABAP

The programming language ABAP has been changing for years and is being modernized in various concepts. In this article, we'll look at it in detail.

06/24/2022

ABAP Quick - Clean Core

Category - ABAP

In this article something about Clean Core, what does it mean for the developer, what are the requirements and what do you have to pay attention to.

06/17/2022