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:

@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);
    }
}

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 BAPIBNAME is a CHAR12, a character sequence (string) of length 12. Example values: "MUELLER" or "000000001001" (with leading zeros).

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 BAPIADDR3 has fields STREET, CITY, COUNTRY etc. that each have their own data element. Example: STREET="Main St", CITY="Berlin".

JCoStructure. Most of the time we will be using its super interface JCoRecord.

Table Type

Defines the structure of an internal table (not a database table) including row type and key. The closest concept in Java is java.util.List.

Table type BAPIADDR3_T is the table type for structure BAPIADDR3. Table types are used for lists of a structure, similar to a list of objects in Java.

JCoTable

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

CHAR (Character), NUMC (Numeric Character)

CHAR(10) for BP numbers, NUMC(5) for zip codes

String, char[]

String

Numeric

DEC (Decimal), INT (Integer), FLOAT (Floating Point)

DEC(10,2) for monetary values, INT(4) for counters

int, byte, short, long, float, double, BigInteger, BigDecimal

int, BigDecimal (we do not use float at this point)

Date and Time

DATS (Date), TIMS (Time)

Dates, timestamps

Date for both, date and time

LocalDate, LocalTime

Boolean

CHAR(1), fixed values 'X' for true and '' for false

Flags, indicators

char

boolean

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

  1. create the JCoFunction object

  2. manipulate its parameter lists

  3. execute the function

  4. 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.