Skip to Content
Technical Articles

Call a Remote Function Module (RFC) From SAP Cloud Platform ABAP Environment – update 09/2020

Earlier this year I wrote a Blog Post covering exactly this topic (find my original Blog Post here). Now – September 2020 – it is already time to provide an update as SAP is innovating quickly and made things more simple.

As Blog Posts can’t be deleted once published and it might be – at least for the time being – good to see how an RFC call to On-Premise had to be implemented before mid Nov 2020 when the SAP Cloud NEO environment was put to rest, I’m not updating my old Blog Post, but rather write a new one.

Before I start, first some context …

SAP’s first Cloud presentation was with the NEO environment. This was SAP’s propriety Cloud runtime. Later SAP added Cloud Foundry which is an open source based industry standard platform. So we had 2 different platforms, providing different services. Before September 10, 2020, it was not possible to submit an RFC call from Cloud ABAP (Foundry based) without NEO. With NEO taken out of the picture, some NEO services were integrated into Foundry, others replaced (example: the NEO based WebIDE was replaced by the new Foundry based Business Application Studio, short BAS).

The good news is that the entire task of a Cloud ABAP RFC call got rid of several complications. Compare with my previous Blog Post and you can see that things are now almost intuitive (other than before!). An earlier prerequisite that you needed to have a Global Enterprise Account is gone as well. You can do all steps with a Trial account !
In addition you might want to check as well SAP’s updated documentation Integrating On-Premise Systems

In the following I will not use the term NEO and Foundry any more. As NEO is history, Foundry is now the one and only SAP Cloud Platform. (well, soon – after mid November 2020)

Ok – let’s start:

In a nutshell, there are the following steps to perform:

  • On-Premise

    • Install SAP Cloud Connector
      • Note: make sure that you have version 2.12.3 or higher installed !
    • Configure your Cloud Connector to connect to your SAP Cloud Subaccount
    • Grant RFC access in Cloud Connector to your on-premise SAP system(s)
  • SAP Cloud Subaccount

    • Verify your active Cloud Connector connection to your On-Premise system
    • Define your Destinations for the RFC call(s) in your Foundry Subaccount
  • Eclipse / ABAP Cloud Project

    • Implement the required ABAP code to obtain the destination for your RFC call

I’m not going to cover the installation of the SAP Cloud Connector. I will just outline how to do the Cloud Connector configuration to connect to your SAP Cloud subaccount and how to add the connectivity to one on-premise SAP system with RFC.

  • Add a new subaccount to the Cloud Connector
    The necessary information for Region and Subaccount you can find in your Cloud Subaccount. In your Subaccount on the side menu choose Overview and find the following:

    Subaccount user is the email address you use to log into the Cloud.
    Description and Location ID is optional, but in case you have multiple Cloud Connector connected to your Cloud subaccount, you need to distinguish them by a Location ID. I choose SAP_FSD for Location ID and Karma as description (you will notice those names in my next screen shots)
  • The result should look like this
    Next select on the left menu the Cloud To On Premise to create the RFC
    Follow the wizard and enter the following values:

    1. Back-end Type = ABAP System
    2. Protocol = RFC
    3. Connection Type – with or without load balancing (I choose without – this influences the next steps a little bit)
    4. Application Server and Instance number according to you backend system – check your SAP GUI for the correct values
    5. Virtual Application server and Virtual Instance Number – these values are defaulted from step 4. But I usually mask these values with a virtual name and instance. Later in the Cloud Subaccount your Cloud Connection overview will show the chosen virtual values
    6. Click Next until you reach the last step and Finish
  • Now it should look like this
    Click the + In the Resources section to add now the RFC function you want to make available. In the following dialog you can choose a single RFC or a generic pattern. I just make the RFC_SYSTEM_INFO available for now. Click Save and you will be here:

The On-Premise Cloud Connector configuration is completed !

 

Now switch to your SAP Cloud subaccount and find your connected On-Premise Cloud Connector in the Connectivity section. Notice that the Location ID is displayed in parenthesis after Master Instance and the exposed host is the masked virtual name from the above RFC config

 

Before we can start coding our ABAP RFC to an on-premise backend system, we need to define the  destination. Click on Destinations in the Connectivity section

Select New Destination and provide the data for your back end SAP system. The Proxy-Type needs to be set to OnPremise. Do not forget to maintain the Additional Properties (click New Property button in order to add/maintain)

  • jco.client.ashost = < your on premise SAP host as defined in the Cloud Connector >
  • jco.client.client   = < SAP Client >
  • jco.client.sysnr   = < SAP System Instance >

If you used – as I did – a Location ID for your Cloud Connector do not forget to enter that as well.

After saving, select the Check Connection and you should see this:

The RFC connectivity is now established. Last thing to do is the ABAP code.

Go to Eclipse and create a new ABAP class and call the RFC_SYSTEM_INFO function module from the On-Premise system.

CLASS zcl_jm_rfc_sys_info DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES if_oo_adt_classrun.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS zcl_jm_rfc_sys_info IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.
    DATA msg       TYPE c LENGTH 255.
    DATA lv_result TYPE c LENGTH 200.

    TRY.
        DATA(lo_rfc_dest) = cl_rfc_destination_provider=>create_by_cloud_destination(
                               i_name = |RFC_FSD| ).

        DATA(lv_rfc_dest) = lo_rfc_dest->get_destination_name( ).
  
        CALL FUNCTION 'RFC_SYSTEM_INFO' DESTINATION lv_rfc_dest
          IMPORTING
            rfcsi_export          = lv_result
          EXCEPTIONS
            system_failure        = 1 MESSAGE msg
            communication_failure = 2 MESSAGE msg
            OTHERS                = 3.

        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.

      CATCH cx_root INTO DATA(lx_root).
        out->write( lx_root->get_text( ) ).
    ENDTRY.
  ENDMETHOD.
ENDCLASS.

That’s it – test your code in Eclipse with F9 and see in the Eclipse console the system info of your remote on-premise system.

Now you know how you can consume any RFC enabled On-Premise function out of your Cloud ABAP application.

 

One last word – as you probably agree after reading through this blog post, this is relatively simple and straight forward to enable RFC calls to an On-Premise system. And you might wonder why this blog post is here in the first place. Well, this is not the first place. See my previous blog post when NEO was around and you will agree that it used to be quite complicated (and not even possible with a Trial account). So this blog post is pretty much a follow up on the first. Not more and not less.

If you are interested in learning more about RAP (Restful ABAP Programming), then I can highly recommend the following Open SAP course: Building Apps with the ABAP RESTful Application Programming Model

Cheers !

3 Comments
You must be Logged on to comment or reply to a post.
  • Hi,

    thank you for the blog post! When using an Enterprise Account, I get the error message ‘Destination service instance not found’, although I have set up the destination in the subaccount. what could be the reason for this? Perhaps missing properties at the destination?

    Kind regards
    Rouzbeh

    • Hi Rouzbeh – sorry for my late reply ….

      The thing is that after all this new feature was rolled out in waves. Please try again. By now it should be finally generally available

      • Hi Jurgen,

        thank you! We opened an SAP ticket and were notified that our system is migrated to the new connectivity approach. Now we can connect to our backend system via an http destination but calling RFC destination always fails with the following error message:

        “exception communication_failure Error when opening an RFC connection (Communication system error.)”

        Since we could not find any log entries in the backend system and the cloud connector, we assume that there is a problem with initiating such a RFC call from ABAPonSCP. Any idea how to debug/fix this issue?

        Kind regards
        Rouzbeh