ABAP Quick - RFC Error handling
How do you actually handle errors when communicating via a destination in the function module? More about this in our tip.
Table of contents
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