First, log into the ABAP on-premises system, run the transaction code: aco_proxy for the RFC functions RFC_SYSTEM_INFO and RFC_READ_TABLE, and generate proxy class metadata in the format of XML. Save the XML file locally.

Use the ABAP Development Tool to log in to the SAP BTP ABAP runtime environment and create a new Service Consumption Model (RFC).

Generate a Proxy Class that we will use later in the ABAP code to call the RFC functions On the on-premises system. Import the metadata. XML generated in the on-premises system in the previous step into the Proxy class generation wizard.

Activate the Service Consumption Model. In the automatically generated proxy class, we can find the ABAP code template. This code template can be directly copied into our ABAP code and modified slightly. You can call the RFC functions of the ABAP on-premises system.

Create a new ABAP class and copy the code from the proxy class above into the Main method of the ABAP class:

The complete code is as follows:

CLASS zcl_consume_rfc DEFINITION PUBLIC FINAL CREATE PUBLIC . PUBLIC SECTION. INTERFACES if_oo_adt_classrun . PROTECTED SECTION. PRIVATE SECTION. ENDCLASS. CLASS zcl_consume_rfc IMPLEMENTATION. METHOD if_oo_adt_classrun~main. DATA dest TYPE  REF TO IF_RFC_DEST. DATA myobj TYPE REF TO ZCL_JERRY_RFC_PROXY. DATA CURRENT_RESOURCES TYPE ZCL_JERRY_RFC_PROXY=>SYST_INDEX. DATA FAST_SER_VERS TYPE INT4. DATA MAXIMAL_RESOURCES TYPE ZCL_JERRY_RFC_PROXY=>SYST_INDEX. DATA RECOMMENDED_DELAY TYPE ZCL_JERRY_RFC_PROXY=>SYST_INDEX. DATA RFCSI_EXPORT TYPE ZCL_JERRY_RFC_PROXY=>RFCSI. DATA S4_HANA TYPE ZCL_JERRY_RFC_PROXY=>CHAR1. TRY. dest = CL_RFC_DESTINATION_PROVIDER=>create_by_cloud_destination( 'AG3' ). CREATE OBJECT myobj EXPORTING destination = dest. catch CX_RFC_DEST_PROVIDER_ERROR. " handle CX_RFC_DEST_PROVIDER_ERROR ENDTRY. TRY. myobj->RFC_SYSTEM_INFO( IMPORTING CURRENT_RESOURCES = CURRENT_RESOURCES FAST_SER_VERS = FAST_SER_VERS MAXIMAL_RESOURCES = MAXIMAL_RESOURCES RECOMMENDED_DELAY = RECOMMENDED_DELAY RFCSI_EXPORT = RFCSI_EXPORT S4_HANA = S4_HANA ). CATCH CX_ACO_COMMUNICATION_FAILURE INTO DATA(lcx_comm). " handle CX_ACO_COMMUNICATION_FAILURE (sy-msg* in lcx_comm->IF_T100_MESSAGE~T100KEY) CATCH CX_ACO_SYSTEM_FAILURE INTO DATA(lcx_sys). " handle CX_ACO_SYSTEM_FAILURE (sy-msg* in lcx_sys->IF_T100_MESSAGE~T100KEY) CATCH CX_ACO_APPLICATION_EXCEPTION INTO DATA(lcx_appl). " handle APPLICATION_EXCEPTIONS (sy-msg* in lcx_appl->IF_T100_MESSAGE~T100KEY) ENDTRY. ENDMETHOD. ENDCLASS.

Note that you need to complete the Destination configuration for ABAP on-premises system AG3 On SAP BTP Cockpit using the SAP Cloud Connector as described in this article.

The reason is that there are two problems when setting up a connection between the SAP BTP, ABAP environment, and internal deployment:

  • The ABAP environment “exists” on the Internet, but the customer’s internal deployment system resides behind the firewall
  • The RFC does not support the Internet

Therefore, you need to establish a secure tunnel connection from the internal deployment system to the SAP BTP, ABAP environment.

  • The ABAP environment tenant obtains the Destination from the Destination service instance.
  • The ABAP environment tenant requests to open the tunnel connection through the Connectivity service.
  • The connection service tells the cloud connector to open a connection to a tenant in this particular ABAP environment using an administrative connection.
  • The cloud connector uses its public tenant URL to open a tunnel connection to an ABAP environment tenant.
  • Once the tunnel is established, it can be used for actual data connections using either RFC or HTTP(S) protocols.

More of Jerry’s original articles can be found on “Wang Zixi “: