Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Data Interfaces and Communication Interfaces →  Remote Function Call →  Examples for Remote Function Call 

Handling Exceptions During RFCs

The example demonstrates the different ways of handling errors during an RFC.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA demo_exception  TYPE REF TO cx_demo_exception.
    DATA msg TYPE c LENGTH 255.

    "Classical exception handling

    CALL FUNCTION 'DEMO_RFM_CLASSIC_EXCEPTION'
      DESTINATION 'NONE'
      EXCEPTIONS
        system_failure        = 1  MESSAGE msg
        communication_failure = 2  MESSAGE msg
        OTHERS                = 3.
    CASE sy-subrc.
      WHEN 1.
        WRITE: / 'EXCEPTION SYSTEM_FAILURE', msg.
      WHEN 2.
        WRITE: / 'EXCEPTION COMMUNICATION_FAILURE', msg.
      WHEN 3.
        WRITE: / 'EXCEPTION OTHERS'.
    ENDCASE.

Description

Function module DEMO_RFM_CLASS_BASED_EXCEPTION triggers the class-based exception CX_DEMO_EXCEPTION. Function module DEMO_RFM_CLASSIC_EXCEPTION triggers the non-class-based exception CLASSIC_EXCEPTION.

EXCEPTIONS is not specified during the first two calls, which means that class-based exceptions are handled:

  • When DEMO_RFM_CLASS_BASED_EXCEPTION is called, any possible class-based exceptions are handled with CATCH. If none of the predefined exceptions of the RFC interface are raised, CX_DEMO_EXCEPTION is caught.
  • Possible class-based exceptions are also handled with CATCH when DEMO_RFM_CLASSIC_EXCEPTION is called. If none of the predefined exceptions of the RFC interface are raised, CX_CLASSIC_EXCEPTION is caught whose attribute EXCEPTION_NAME contains the name of the original classic exception.

EXCEPTIONS is specified during the other two calls, which means that non-class-based exceptions are handled:

  • When DEMO_RFM_CLASS_BASED_EXCEPTION is called, predefined exception SYSTEM_FAILURE of the RFC interface is raised because class-based exception CX_DEMO_EXCEPTION cannot be handled.
  • When DEMO_RFM_CLASSIC_EXCEPTION is called, possible classic exceptions are assigned values for sy-subrc. If none of the predefined exceptions of the RFC interface are raised, sy-subrc is set to "4".