What is RFC and discover different interfaces of RFC

What is RFC?
A Remote Function Call(RFC) is a call to a function module running in a system different from the caller’s. The remote function can also be called from within the same system (as a remote call).The RFC interface provides the ability to call remote functions.

RFC consists of two interfaces :

  1. A calling interface for ABAP Programs
  2. A calling interface for Non-SAP programs.

Any ABAP program can call a remote function using the CALL FUNCTION…DESTINATION statement. The DESTINATION parameter tells the SAP System that the called function runs in a system other than the caller’s.
Syntax-

CALL FUNCTION ‘remotefunction’
DESTINATION dest
EXPORTING f1 =
IMPORTING f2 =
TABLES t1 =
EXCEPTIONS
Logical Destinations are defined via transaction SM59 and stored in Table RFCDES

Functions of the RFC interface

  • Converting all parameter data to the representation needed in the remote system
  • Calling the communication routines needed to talk to the remote system.
  • Handling communications errors, and notifying the caller, if desired ( using EXCEPTIONS paramater of the CALL FUNCTION).

Types of RFC

  1. Synchronous RFC – The calling program continues the execution only after the called function is complete.
  2. Asynchronous RFC – The calling program continues the execution without waiting for return from the called function.
  3. Transactional RFC – The called function module is executed exactly once in the RFC target system.Each function call is seen as a transaction in the target system. Transactional RFCs use the suffix IN BACKGROUND TASK . Eg : CALL FUNCTION ‘remotefunction’ IN BACKGROUND TASK

How to Code an RFC ?
1. In the function module attributes tab (transaction code SE37), set the processing type as Remote-enabled module to create a remote function module.

What is RFC and discover different interfaces of RFC

2. Write the code for the function module.

What is RFC and discover different interfaces of RFC

3. Define the destination of the RFC server in the RFC client system that calls the remote function ( via SM59 transaction).

What is RFC and discover different interfaces of RFC

4 .Declaring Parameters: All parameter fields for a remote function module must be defined as reference fields, that is, like ABAP Dictionary fields.
5. Exceptions: The system raises COMMUNICATION_FAILURE and SYSTEM_FAILURE internally. You can raise exceptions in a remote function just as you would in a locally called function.

Debugging Remote Function Calls

  • It is not possible to debug a remote function call to another system.
  • However, when testing ABAP-to-ABAP RFC calls, you can use the ABAP debugger to monitor the execution of the RFC function in the remote system.
  • With remote calls, the ABAP debugger (including the debugging interface) runs on the local system. Data values and other run information for the remote function are passed in from the remote system.