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: 

handle timeout exception in rfc call

Former Member
0 Kudos

Dear SAP Experts,

I have been searching for a while and could not find a satisfactory answer to my problem.

I use SAP - CRM and call other SAP and non-SAP systems via RFC.

I need to handle all exceptions, otherwise WEB UI displays a full page exception details, which is unacceptable on a production system.

I have the following piece of code:


 CALL FUNCTION FUNCTION_NAME DESTINATION DEST
    EXPORTING
      S_IMPORT              = INPUT_DATA 
    IMPORTING
      S_EXPORT              = OUTPUT_DATA
    EXCEPTIONS
      SYSTEM_FAILURE        = 1  MESSAGE err_msg " catch system failure
      COMMUNICATION_FAILURE = 2  MESSAGE err_msg " catch communication errors
      OTHERS                = 99.                " catch everything else

It handles most of exceptions, however, it cannot process timeouts. Is there a way to handle timeout in ABAP RFC call? Is timeout exception uncatchable? If so is there a way around?

Can you please suggest some solution as I am running out of ideas.

Regards,

Dominik

2 REPLIES 2

Former Member
0 Kudos

I have found a solution. To approach this I use asynchronous function call.


 TRY.
    CALL FUNCTION ZZ_TEST_TIMEOUT' DESTINATION lv_dest STARTING NEW TASK 'TIMEOUT_TASK'
    CALLING me->callback ON END OF TASK
        EXCEPTIONS
          SYSTEM_FAILURE        = 1  MESSAGE err_msg " catch system failure
          COMMUNICATION_FAILURE = 2  MESSAGE err_msg " catch communication errors
          OTHERS                = 99.                " catch everything else

        WAIT UNTIL READY EQ 'X' UP TO 55 SECONDS.
        IF READY NE 'X'.
          RAISE EXCEPTION TYPE CX_TIMEOUT.
        ELSE.
          WRITE / 'success'.
        ENDIF.
  CATCH CX_ROOT INTO OREF.
   WRITE / 'TIMEOUT EXCEPTION'.
 ENDTRY.

callback sets variable READY to abap_true when data is received.

The trick is to use UP TO 55 SECONDS. after wait, which is shorter than the server timeout. This terminates function call and gives opportunity to code your own timeout behavior.

Former Member
0 Kudos

Solution in second post