Skip to Content

Call a Remote Function Module From SAP Business Technology Platform (BTP), ABAP Environment

Requires Customer/Partner License
Call a remote function module located in an on-premise system, such as a SAP S/4HANA System, from the ABAP Environment.
You will learn
  • How to open a secure tunnel connection between your SAP BTP, ABAP Environment and an on-premise SAP System, e.g. SAP S/4HANA
  • How to create a destination service instance with an RFC connection
  • How to test the connection using an ABAP handler class
julieplummer20Julie PlummerJanuary 25, 2022
Created by
April 29, 2019


Throughout this tutorial, replace XXX or JP with your initials or group number.

The problem:

There are two problems when setting up connectivity between the SAP BTP, ABAP Environment and an on-premise:

  • The ABAP Environment “lives” in the Internet, but customer on-premise systems are behind a firewall
  • Remote Function Call (RFC) is not internet-enabled

The solution:

  • Set up a secure, tunnel connection from the on-premise system to the SAP BTP, ABAP Environment


  1. The ABAP environment tenant fetches the destination from the Destination service instance.
  2. The ABAP environment tenant requests to open the tunnel connection through the Connectivity service.
  3. The Connectivity service tells the Cloud Connector to open the connection to this specific ABAP environment tenant using the admin connection.
  4. The Cloud Connector opens a tunnel connection to the ABAP environment tenant using its public tenant URL.
  5. After the tunnel is established, it can be used for actual data connection using the RFC or HTTP(S) protocols.
Image depicting overview-cf-only

More Information

This tutorial mission is based on a blog post series by Andre Fischer, which is well worth a look:

For more information on OData services and SAP Gateway in general, see:
- OData service development with SAP Gateway using CDS - pertains to on-premise Systems, but contains lots of useful background information on the relationships between CDS views and OData services

For more information on connectivity in this context, see:
- SAP Help Portal: SAP Cloud Connector

For more information on SAP Business Technology Platform (BTP)
- SAP Help Portal: What is SAP Business Technology Platform (BTP)

  • Step 1

    First, you need to connect your ABAP on-premise system to a Cloud Foundry subaccount by means of SAP Cloud Connector.

    1. In your browser, log on to SAP Cloud Connector:

      • Address = e.g. https://localhost:<port> (Default = 8443)
      • User = Administrator
      • Initial password = manage (You will change this when you first log in)
    2. Choose Add Subaccount:

      Field Name Value
      Region Your region. You can find this in SAP BTP cockpit (see screenshot below) - e.g. here, Europe (Frankfurt) - AWS
      Subaccount Cloud Foundry Subaccount ID. You can find this by choosing your subaccount in SAP BTP cockpit and choosing the information (i) icon. (see screenshot below)
      Display Name (Subaccount) Display Name. You can find this in by choosing your subaccount in SAP BTP cockpit (see screenshot below)
      Subaccount User
      Location ID Optional here. However, it is mandatory if you want to connect several Cloud Connectors to your subaccount. This can be any text, e.g. XXX for your initials or group number as here

    Your configuration should now look like this. Note down the Location ID, here XXX. You will need it later.


  • Step 2
    1. In the menu in the left pane, expand the subaccount and choose Cloud To On-Premise > Access Control.

      Image depicting step2a-cf-add-onP-system
    2. In the Mapping Virtual to Internal System pane, choose Add (+).

    3. Enter the following values, and choose Save.

      Field Name Value
      Backend Type ABAP
      Protocol RFC
      Without Load Balancing
      Application Server IP address of the on-premise server, e.g. of NPL
      Instance Number 00
      Virtual Host e.g. nplhost. This represents an external hostname, so that you can hide the internal hostname from the outside world. You will need this external hostname and port later, when creating a destination from SAP BTP cockpit.
      Virt. Inst. No. 00
      Principal Type None
      Description Optional
      Check Internal Host Ticked

    The mapping should now look something like this. Check that the status = Reachable. If not, check that you chose the correct port, or whether an internal firewall is preventing communication:

  • Step 3

    Now, still in the Cloud to On-Premise > Access Control tab, enter the resource you need, RFC_SYSTEM_INFO.

    1. Add the resource RFC_SYSTEM_INFO by choosing the Protocol = RFC, then choosing +.

    2. Enter the name of the RFC, e.g. RFC_SYSTEM_INFO. Alternatively, add RFC as a Prefix. Then choose Save

    3. Add BAPIs to the list of resources by choosing + again. (You will need this BAPI in a later tutorial.)

    4. Enter the name BAPI_EPM as a Prefix, then choose Save.

    5. The list of resources should now look roughly like this.

  • Step 4

    In the SAP BTP cockpit of your Cloud Foundry subaccount, choose Cloud Connectors:


    The location ID points to the correct SAP Cloud Connector (located in the on-Premise system); The virtual host points to the on-Premise connection mapped in SAP Cloud Connector.

  • Step 5

    You will now create a destination in the ABAP Environment. This must be created at subaccount (not Space) level.

    1. In the SAP BTP cockpit of your Cloud Foundry subaccount, choose Destinations, then choose New Destinations.

    2. Enter the following values:

      Field Name Value
      Name e.g. NPL_JP as here
      Type RFC
      Description Can be anything, here NPL
      Location ID same as in step 1, e.g. XXX
      User Your user for the on-premise system, e.g. DEVELOPER
      Password Your password
    3. Add the following additional properties and values, by choosing New Property:

      Field Name Value
      jco.client.ashostVirtual hostname of your on-premise ABAP System, defined in SAP Cloud Connector, e.g. <nplhost>
      jco.client.client<Your ABAP System client, e.g. 001
      jco.client.sysnr <Your ABAP System number>, e.g. 00



  • Step 6
    1. Create a new ABAP class: Choose File > New > Other… > ABAP Class.

    2. Enter a name and description. The name should be in the form ZCL_...RFC_XXX. Replace XXX with your group number or initials.

    3. Create or assign a transport request.

  • Step 7
    1. Implement the interface by adding this statement to the public section:

      interfaces if_oo_adt_classrun.

      This allows you to test your class by displaying the output in the ABAP Console.

    2. In the implementation section, add the METHOD and ENDMETHOD statements:


  • Step 8

    Create the data types that specify your remote connection information, replacing the i_name with your the name of the specific RFC destination, which you created in SAP BTP cockpit (in step 5 of this tutorial).

    DATA(lo_destination) = cl_rfc_destination_provider=>CREATE_BY_CLOUD_DESTINATION(
                            i_name                  = 'NPL_JP'
    DATA(lv_destination) = lo_destination->get_destination_name( ).
    DATA lv_result type c length 200.
  • Step 9
    CALL function 'RFC_SYSTEM_INFO'
    destination lv_destination
        RFCSI_EXPORT      = lv_result.
  • Step 10

    Output the result of the RFC call to the ABAP Console

    out->write( lv_result ).
  • Step 11

    Wrap the whole method in an exception using TRY…CATCH.

    catch cx_root into data(lx_root).
      out->write( lx_root->get_text( ) ).
    Image depicting step15-try-catch
  • Step 12

    Your code should look roughly like this:

      create public .
    public section.
      interfaces if_oo_adt_classrun.
    protected section.
    private section.
          DATA(lo_destination) = cl_rfc_destination_provider=>CREATE_BY_CLOUD_DESTINATION(
                                  i_name                  = 'NPL_JP'
          DATA(lv_destination) = lo_destination->get_destination_name( ).
          DATA lv_result type c length 200.
          CALL function 'RFC_SYSTEM_INFO'
          destination lv_destination
              RFCSI_EXPORT      = lv_result.
            out->write( lv_result ).
        catch cx_root into data(lx_root).
          out->write( lx_root->get_text( ) ).
  • Step 13
    1. Save and activate the class, using Ctrl+S, Ctrl+F3.

    2. Run the class by choosing F9. Some system information, such as the hostname, the System ID ( <SID> ), and the IP address should be displayed.

  • Step 14

    When creating a destination in SAP Cloud Cockpit, which information do you require from SAP Cloud Connector in your on-Premise system. Choose all that apply:

  • Step 15
    1. Go back to your RFC class. Remove the period (.) after the IMPORTING parameter and add the following exception parameters to the function call RFC_SYSTEM_INFO:


      EXCEPTIONS system_failure = 1 MESSAGE msg communication_failure = 2 MESSAGE msg OTHERS = 3.
    2. Now evaluate sy-subrc by adding the following CASE…ENDCASE statement:


      CASE sy-subrc. WHEN 0. out->write( lv_result ). WHEN 1. out->write( |EXCEPTION SYSTEM_FAILURE | && msg ). WHEN 2. out->write( |EXCEPTION COMMUNICATION_FAILURE | && msg ). WHEN 3. out->write( |EXCEPTION OTHERS| ). ENDCASE.
      Image depicting step20-error-handling
Back to top