@Service
public class MyService {
private final JcoFunctionExecutorFactory factory;
public Result callRfc(String input) {
return factory.create("RFC_NAME")
.parameters(fn -> fn.getImportParameterList().setValue("PARAM", input))
.execute(() -> "Unable to call RFC for input '%s'".formatted(input))
.to(this::mapResult);
}
}
Appendix
SAP Remote Function Calls
This chapter explains how to call SAP Remote Function Calls (RFCs) using SAP Java Connector (JCo) and the Faktor Zehn JCo library. It covers ABAP Function Modules and their semantics, the SAP Data Dictionary (DDIC), type conversions, leading zero handling, transactional behavior, and best practices for RFC integration.
Prerequisites
Before working with RFC calls, ensure you have:
-
SAP JCo library installed and configured (see [install-jco])
-
Access to SAP system credentials and connection details
-
Knowledge of the specific RFCs you need to call
-
Understanding of the business domain and data requirements
Quick Start
The following example shows how to make a simple RFC call:
For details, see [faktorzehn-jco-library].
Introduction to ABAP FMs, RFCs and the Data Dictionary
ABAP is one of SAP’s proprietary programming languages. In ABAP, a Function Module (FM) is a reusable procedure that encapsulates specific logic and can be called independently. Unlike pure functions in functional programming, FMs can be stateful and have side effects. The closest concept in Java is a static method in a class with static fields, which can maintain state and produce side effects.
A Function Module that is enabled to be called remotely is called a Remote Function Call (RFC).
An FM call in ABAP looks like this:
DATA: lv_username TYPE BAPIBNAME,
lt_address TYPE BAPIADDR3_T,
lt_return TYPE BAPIRET2.
lv_username = 'some_user'.
CALL FUNCTION 'BAPI_USER_GET_DETAIL'
EXPORTING
USERNAME = 'some_user'
IMPORTING
RETURN = lt_return
TABLES
ADDRESS = lt_address
EXCEPTIONS
USER_NOT_FOUND = 1
OTHERS = 2.
IF sy-subrc <> 0.
" Handle exceptions
ENDIF.
An FM has a name and consists of the following components:
-
Import Parameters: The input parameters that the FM accepts.
-
Export Parameters: The output parameters that the FM returns after execution.
-
Changing Parameters: The parameters that the FM accepts and can change.
-
Tables: Lists of data of the same structure used to pass to and from the FM. Also changeable.
-
Exceptions: Numerical return codes to indicate exceptions, can be checked via system field
sy-subrc.
Data Dictionary Type
Parameters can be of different types defined in the so-called ABAP Data Dictionary (DDIC).
| DDIC Type | Description | Example | JCo Interface |
|---|---|---|---|
Data Element |
Defines a single field and its domain. Internal and external representations can differ, see section Leading Zeros. |
Data element |
See Data Domains. |
Structure |
A complex data type that consists of multiple fields (called components) grouped together. Fields can be of any type: data elements, structures or table structures. |
Structure |
|
Table Type |
Defines the structure of an internal table (not a database table) including row type and key. The closest concept in Java is |
Table type |
|
Data Domains
A domain defines the technical properties of a field, such as data type, length, decimal places and possible values. Domains ensure consistency and validation of data across different fields. The DDIC provides several types of domains. The following table provides an overview of the most relevant domain types for our purposes as well as their representation in JCo and our choice. The conversion is described in a later section.
| Domain Type | Data Types | Example | JCo Types | Our Choice |
|---|---|---|---|---|
Character |
|
|
|
|
Numeric |
|
|
|
|
Date and Time |
|
Dates, timestamps |
|
|
Boolean |
|
Flags, indicators |
|
|
| There are several other domain types we do not use directly. |
Introduction to SAP JCo
SAP Java Connector (JCo) is a Java library to call RFCs (remote-enabled FMs) provided by a SAP systems.
The Java interface representing an FM is com.sap.conn.jco.JCoFunction.
Its most important methods are:
JCoParameterList getImportParameterList();
JCoParameterList getExportParameterList();
JCoParameterList getChangingParameterList();
JCoParameterList getTableParameterList();
AbapException[] getExceptionList();
void execute(JCoDestination jCoDestination);
| Its javadoc is part of the zip file. |
To call an RFC from Java we have to
-
create the
JCoFunctionobject -
manipulate its parameter lists
-
execute the function
-
read and process the exceptions and parameter lists
This can be quite imperative and cumbersome. That’s why the FS-CD Adapter provides a Java library built on top of SAP JCo.
See Faktor Zehn JCo Library for the higher-level wrapper API.