Skip to Content
Technical Articles
Author's profile photo ankit agarwal

SAP Cloud Foundry To On-Premise RFC Connection Using JCo

The SAP Java Connector (SAP JCo) is a development library that enables development of SAP compatible components in Java. It can be used to communicate with on-premise SAP systems via SAP’s RFC protocol.


In this tutorial, we are going to learn how can we call a function module in an on-premise ABAP system by SAP JCo (Inbound).

Let’s go step by step.

  • Step 1: As a starting point, I build a maven web project with the following code:
package com.test.jco;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



public class ConnectRFC extends HttpServlet {

    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter responseWriter = response.getWriter();

        try {

            // access the RFC Destination "Test"
            JCoDestination destination = JCoDestinationManager.getDestination("Test");

            // make an invocation of STFC_CONNECTION in the backend
            JCoRepository repo = destination.getRepository();
            JCoFunction stfcConnection = repo.getFunction("STFC_CONNECTION");

            JCoParameterList imports = stfcConnection.getImportParameterList();
            imports.setValue("REQUTEXT", "JCO successful");


            JCoParameterList exports = stfcConnection.getExportParameterList();
            String echotext = exports.getString("ECHOTEXT");
            String resptext = exports.getString("RESPTEXT");

        } catch (Exception e) {





The explanation goes as follows:

  1. “Test” is the name of the destination which will be used after a few steps.
  2. “STFC_CONNECTION” is a standard ABAP function module, which I am using here to test the connectivity.

Following JCo dependency needs to be included in your project.



  • Step 2: Now we need to log into the SAP CF subaccount, where we want to deploy our application. Here we need to create and bind instances for the following three services:
    • Connectivity Service
    • Destination Service
    • XSUAA service

I have created these service instances and named them as following – jco_con , jco_dest, and jco_xs. Select the service plan as application and Provide the following configuration in parameters while creating xsuaa instance. Here “connect-rfc” is the app name by which I will deploy my java application in CF.

    "xsappname" : "connect-rfc",
    "tenant-mode": "dedicated",
    "scopes": [
            "name": "$XSAPPNAME.all",
            "description": "all"


  • Step 3: Now deploy the war file to the subaccount with the following manifest.yml configuration.



- name: connect-rfc


  - sap_java_buildpack


    SAP_JWT_TRUST_ACL: '[{"clientid":"*","identityzone":"*"}]'

    xsuaa_connectivity_instance_name: "jco_xs"


    - jco_xs

    - jco_con

    - jco_dest


  • Step 4: Create a node (approuter ) ** . Make necessary arrangements into xs-app.json (Point the URL to the destination). Finally, Deploy this in the subaccount with the following manifest.yml configuration.
    - name: approuter-jco
      path: ./
      - nodejs_buildpack
      memory: 120M
        destinations: >
             {"name":"dest", "url" :"https://<your java application url>/ConnectRFC", "forwardAuthToken": true }
        - jco_xs​

    When choosing the application route, you are requested to login. Provide the credentials known by the IdP you configured in Roles & Trust. After successful login, you are routed to the java application which is then executed. It prompts an error that destination “Test” does not exist, which is obvious as we didn’t create a destination till now.

  • Step 5: Create an RFC destination named “Test” in your destination instance.
  • Step 6: Configure the system mapping and the function module in the Cloud Connector. Provide access to the function module “STFC_CONNECTION”.


cloud connector


SAP Cloud Platform – CF


  • Step 7: Run approuter, provide the credentials. This time you will receive the output of your Servlet. I received the following output.
JCO successful:SAP R/3 Rel. 752   Sysid: XXX      Date: 20200725   Time: 110012   Logon_Data: 100/XXXX/E


Note : In this tutorial, I used approuter for authentication purpose. You can use AppToAppSSO to propagate authentication token. Token is required for On-Premise connectivity.


**Follow the steps in Application Router or use the demo file (download).

With this, I would like to conclude the tutorial. For more details, follow the below links :



Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Rahul Yadav
      Rahul Yadav

      Thanks Ankit.

      Well explained.

      Author's profile photo Michael Smith
      Michael Smith

      ankit agarwal , is the AppToAppSSO option still available for Cloud Foundry?  I do not see it listed in the authentication options when I attempt to create the destination.