Skip to Content
Technical Articles
Author's profile photo Jurgen Meinshausen

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 !

Assigned Tags

      12 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Rouzbeh Nabatian
      Rouzbeh Nabatian

      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

      Author's profile photo Jurgen Meinshausen
      Jurgen Meinshausen
      Blog Post Author

      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

      Author's profile photo Rouzbeh Nabatian
      Rouzbeh Nabatian

      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

      Author's profile photo Torsten Fenske
      Torsten Fenske

      Thank you for this very helpful blog post. Perhaps one remark if you already used the old way.

      Also, make sure that no communication arrangement to the deprecated communication scenario SAP_COM_0200 exists.

      Otherwise the new scenario does not work.

       

      Kind regards

      Torsten

      Author's profile photo Sumanth Kristam
      Sumanth Kristam

      is it possible to call the SAP which is deployed in cloud via RFC? Say from 3rd party software?

      Author's profile photo Jurgen Meinshausen
      Jurgen Meinshausen
      Blog Post Author

      With the SAP Cloud Connector you can access as well RFCs in the cloud (I described the cloud to on-premise consumption. But the Cloud Connector works both ways). But the proper way - and state of the art - would be to consume/define an Odata service. Especially if data is to be made available to 3rd party consumers. The new ABAP Restful Programming model (i.e. ABAP in the cloud) allows you to define such service in a pretty simple and straight forward fashion

      Author's profile photo Bharath Nagaraj
      Bharath Nagaraj

      HI, Is there a way to connect Odata service from backend system instead of RFC FM?

      Author's profile photo Jurgen Meinshausen
      Jurgen Meinshausen
      Blog Post Author

      of course - that is the classic (consuming RFC was a bit more complicated). You either consume the odata service via a public url:

      • DATA(lo_http_destination) = cl_http_destination_provider=>create_by_url( '...public url to your odata service ....' ).

      or (preferred) you define a destination and use that one:

      • DATA(lo_http_destination) = cl_http_destination_provider=>create_by_cloud_destination(
        
               i_name = '.......' " <-- your destination name 
        
               i_authn_mode = if_a4c_cp_service=>service_specific ). 
        

      The rest is as usual:

      "create HTTP client by destination
      DATA(lo_web_http_client) = cl_web_http_client_manager=>create_by_http_destination( lo_http_destination ) . 
      
      "set request method and execute request
      DATA(lo_web_http_response) = lo_web_http_client->execute( if_web_http_client=>get ).
      DATA(lv_response) = lo_web_http_response->get_text( ).
      out->write( |response: { lv_response }| ). 

       

      Author's profile photo Bharath Nagaraj
      Bharath Nagaraj

      Thanks for your response Jurgen. This was very helpful

      Author's profile photo Vijay Sharma
      Vijay Sharma

      Thanks Jurgen for sharing!

      I am facing an error "RFC Destination S4H_RFC not found". I have setup the cloud connector and destination and the test connection is also successful . But getting error when executing the Class.

      I am trying it in BTP trial account. I am not sure if it because of that or i missed something else. If you could please suggest.

      Regards

      Vijay

      Author's profile photo Bodhisattwa Pal
      Bodhisattwa Pal

      Hello Jurgen Meinshausen

      So I have been implementing RAP .

      We have BTP as side by side with S/4 HANA On Prem .

      Now it seems if we call an Odata to the on prem directly in "Create" implementation in the behavior pool  it gives an error because of the "COMMIT WORK" statement  somewhere in the standard code 

      This problem was discussed by

      Umut  Yazici  

      Umut Yazici

      Johann Fößleitner

      Johann Fößleitner

      and the solution is to wrap the BAPI or Odata call in a RFC and call it with destination 'NONE'

      So I decided to wrap my OData call in a FM and call it with destination NONE .

       

      CALL FUNCTION 'Z_ODATA_CREATE_FM' DESTINATION 'NONE'

      It gave me a dump . Screenshot below 

      I removed the NONE and it is working fine , rather  it is going inside the FM .   .

      Now my question is :-

      Is that  adding 'NONE'  --  A  solution only for RAP on On-Prem , it cannot be applied to ABAP on cloud (BTP environment ) ?

      What was i doing wrong . and will removing the 'NONE' solve my problem ?

      If I put the OData call in a FM in SAP BTP Environment and call it without  NONE  will that not give me the error because of the 'COMMIT WORK' ?

      Author's profile photo ANJITHA V A
      ANJITHA V A

      Hi,

      Thank you for the blog.

      how we can add RFC call in our implementation class in create method? We get an error while doing that.