08-23-2007 9:47 AM
Dear All,
I'm doing one report which calls RFC enabled Z function module.
The function module is connecting to another SAP system through Logical system name.
If the connection fails, then I need to pass an error message.
Can anyone please tell me the FM name or way to do it?
Points will be rewarded for the correct solution.
Thanks in advance.
Regards,
Neeraj
08-23-2007 10:10 AM
Hi Neeraj
For every RFC function call you need handle two additional exceptions apart from what is being used in that FM. These exceptions are,
1) SYSTEM_FAILURE
2) COMMUNICATION_FAILURE
But these exceptions should not be mentioned in the Exception tab while creating this RFC enabled FM. So, if the other logical system is down or some problem in connecting to this logical system, these exceptions shall be raised. And you can check by the return variable SY-SUBRC.
Rewards points for all useful answers !!
~Ranganath
08-23-2007 10:19 AM
Hello Neeraj
RFC-enabled function modules should not raise exception within their coding because otherwise the RFC connection will break down. Therefore, your z-function module should not have any exceptions. Instead collect A/E/X messages and return them - like BAPIs do - in an TABLES or EXPORTING parameter of type BAPIRET2 (or BAPIRETTAB).
Call your function module like this:
DATA:
ld_rfc_failure TYPE bapi_msg,
lt_return TYPE bapirettab.
CALL FUNCTION 'Z_MY_RFC_FUNC'
DESTINATION 'rfc destination'
EXPORTING
...
IMPORTING
...
et_return = lt_return " collected messages
TABLES
...
EXCEPTIONS
system_failure = 1 MESSAGE ld_rfc_failure
communication_failure = 2 MESSAGE ld_rfc_failure.
LOOP AT lt_return TRANSPORTING NO FIELDS
WHERE ( type CA 'AEX' ). " A/E/X message
EXIT.
ENDLOOP.
IF ( syst-subrc = 0 ).
" error occured -> error handling
ENDIF.
The longtext of the RFC failure can be captured using the MESSAGE option.
Regards
Uwe