Skip to Content

Call a Remote Function Module From ABAP Environment

test
0 %
Call a Remote Function Module From ABAP Environment
Details
// Explore More Tutorials

Call a Remote Function Module From ABAP Environment

Requires Customer/Partner License

09/30/2019

Call a remote function module located in an on-Premise system, such as an S/4HANA System, from the ABAP Environment

You will learn

  • How to open a secure tunnel connection between your SAP Cloud Platform ABAP Environment and an on-premise SAP System, e.g. SAP S/4HANA
  • How to create a destination service instance with HTTP and RFC connections
  • How to create a communication arrangement to integrate this destination service
  • How to create a communication arrangement to integrate SAP Cloud Connector
  • How to test the connection using an ABAP handler class

For more information on setup, see:

To see this tutorial group as a blog series by Andre Fischer, see:

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

The problem:

There are two problems when setting up connectivity between the Cloud Platform ABAP Environment and an on-premise:

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

The solution:

  • Set up a connection from the on-premise system to the SAP Neo Environment using SAP Cloud Connector.
  • Set up a connection from the SAP Neo to SAP Cloud Foundry Environment.

Specifically:

  1. Fetch the destination, i.e. from Cloud Foundry to on-premise (using a Cloud Foundry destination service)
  2. Send request to open a tunnel, from Cloud Foundry (i.e. ABAP) to Neo
  3. Send request to open a tunnel, from Neo to the on-premise system
  4. Open a secure tunnel for HTTP and RFC
  5. Communicate through the tunnel via HTTP or RFC
Image depicting overview
Step 1: Configure SAP Cloud Connector

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

  1. Log on to SAP Cloud Connector:

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

  • Region = Your region. You can find this in SAP Cloud Cockpit (see screenshot below). Note that your Neo and Cloud Foundry accounts need to run in the same region (e.g. here, Europe Rot)
  • Subaccount = “Neo Technical Name”. You can find this by choosing your SAP Cloud Platform, NEO, subaccount in SAP Cloud Cockpit and choosing the information (i) icon. (see screenshot below)
  • Display Name = (Neo Subaccount) Display Name. You can find this in by choosing your SAP Cloud Platform, NEO, subaccount in SAP Cloud Cockpit (see screenshot below)
  • Subaccount User = for the Neo Subaccount
  • Password
  • 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. here, MyInstance

Image depicting step1g-create-subacc
.
Image depicting step1f-choose-subacc
.
Image depicting step1b-neo-tech-name

Your configuration should now look like this:

Image depicting step1-check-scc

Log on to answer question
Step 2: Add your on-Premise System
  1. In your sub-account (**Display Name**), choose Cloud to On-Premise > Access Control.

    Image depicting step2e-add-onP-system
  2. In the Mapping Virtual… pane, choose Add (+).

    Image depicting step2f-add-2
  3. Enter the following values, and choose Save.

    • Backend Type = ABAP
    • Protocol = RFC
    • Internal Host and port (see below)
    • Virtual Host = e.g. myHost. Here, myHost 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.
    • Virtual Port = usually, enter the internal Port
    • Principal Type = None
    • Check Internal Host = Ticked
    Image depicting step2g-map-internal-system
  4. To find the port, in your on-premise system, choose the transaction SMICM > Goto > Services, then choose an active HTTP port.

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:

Image depicting step1a-scc-resources-sid
Log on to answer question
Step 3: Specify the remote function modules and BAPIs

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 +.

    Image depicting step1d-new-rfc
  2. Enter the name of the RFC, e.g. RFC_SYSTEM_INFO. Alternatively, add RFC as a Prefix. Then choose Save

    Image depicting step1e-name-rfc
  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 like this:

    Image depicting step1e-name-rfc
Log on to answer question
Step 4: Open the destination service instance

You will now create two destinations in the ABAP Environment. These must be created at Space level, e.g. Dev, not subaccount level.

  1. In SAP Cloud Cockpit, open your ABAP Environment > your space, such as Dev, then choose Service Instances.

    Image depicting step2b-service-marketplace
  2. Open the destination service you created in Create a Communication Arrangement for Outbound Communication

    Image depicting step2c-destination-service-instance
  3. Create a new destination for the destination service instance

    Image depicting step3a-new-destination
Log on to answer question
Step 5: Create a new RFC destination for the destination service instance
  1. Again, choose New Destination and enter the following values:

    • Name, e.g. : ES5_RFC_XXX
    • Type: RFC
    • Description, e.g. Test ES5
    • Location ID: same as in step 1, e.g. MyInstance
    • User: Your user for the on-premise system
    • Password: Your password
  2. Add the following additional properties and values, by choosing New Property:

    • jco.client.ashost = <myHost> - again, the external hostname of your on-premise ABAP System in lower-case
    • jco.client.client = <Your ABAP System client, e.g. 002
    • jco.client.sysnr = <Your ABAP System number>, e.g. 11
    Image depicting step5-rfc-destination

You have now created a destination service instance destination for your communication arrangement. Take note of the name, here ES5_RFC_XXX, since you will need it later.

Log on to answer question
Step 6: Create a Communication System for SAP Cloud Connector

(When you created the Communication System for outbound communication, you created the Arrangement first, then the System. This time, it is easiest to create the System first, then the Arrangement.)

  1. Go back to your space Dev and choose Service Instances, then choose your abap service instance, e.g. T02.

    Image depicting step6-open-t02
  2. Open the Dashboard.

    Image depicting step6-open-dashboard
  3. In the Dashboard, choose Communication Systems > New.

  4. Enter the credentials for the SAP Cloud Connector administration user for your SAP CP Neo account (i.e. the same user as in step 1 above):

    • Hostname

      Image depicting step8b-comm-system-1
    • User and Password

      Image depicting step8c-comm-system-2
Log on to answer question
Step 7: Create a Communication Arrangement for SAP Cloud Connector
  1. Go back to the Dashboard Home, choose Communication Arrangements again, then choose New.

    Image depicting step6b-comm-arrangement

  2. Enter the following values and choose Create.

    • Scenario: SAP_COM_0200 (SAP Cloud Connector Integration)
    • Name: SAP_COM_0200_XXX
  3. Enter the Communication System you have just created.

  4. In the details screen, enter the Account Name: <NEO Technical Name>

    Image depicting step7-comm-arrangement-0200-details

Log on to answer question
Step 8: Create an ABAP class for the RFC connection
  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.

Log on to answer question
Step 9: Add the interfaces statement; implement the main method
  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:

    METHOD IF_OO_ADT_CLASSRUN~MAIN.
    ENDMETHOD.

Log on to answer question
Step 10: Create variables
  1. Create the data types that specify your remote connection information.

    DATA(lo_destination) = cl_rfc_destination_provider=>CREATE_BY_CLOUD_DESTINATION(
                            i_name                  = 'ES5_RFC_XXX'
                            i_service_instance_name = 'OutboundComm_for_RFCDemo_XXX'
                           ).
    
    DATA(lv_destination) = lo_destination->get_destination_name( ).
    
    DATA lv_result type c length 200.
    
  2. Replace the i_service_instance_name with your service instance name, specified in the Communication Arrangement, which you created in Create a Communication Arrangement for Outbound Communication.

    Image depicting step10a-service-instance-name-cropped
  3. Replace the i_name with your the name of the specific RFC destination, which you created in step 5 above.

    Image depicting step10b-i-name
Log on to answer question
Step 11: Call the remote function from the on-premise system
CALL function 'RFC_SYSTEM_INFO'
destination lv_destination
  IMPORTING
    RFCSI_EXPORT      = lv_result.

Log on to answer question
Step 12: Output the result

Output the result of the RFC to the ABAP Console

out->write( lv_result ).
Log on to answer question
Step 13: Wrap the method in an exception

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

catch cx_root into data(lx_root).
  out->write( lx_root->get_text( ) ).
endtry.
Image depicting step15-try-catch
Log on to answer question
Step 14: Check your code

You code should look roughly like this:

class ZCL_A4C_RFC_XXX definition
  public
  final
  create public .

public section.
  interfaces if_oo_adt_classrun.
protected section.
private section.
ENDCLASS.



CLASS ZCL_A4C_RFC_XXX IMPLEMENTATION.
  METHOD IF_OO_ADT_CLASSRUN~MAIN.
    TRY.
      DATA(lo_destination) = cl_rfc_destination_provider=>CREATE_BY_CLOUD_DESTINATION(
                              i_name                  = 'ES5_RFC_XXX'
                              i_service_instance_name = 'OutboundComm_for_RFCDemo_XXX'
                             ).

      DATA(lv_destination) = lo_destination->get_destination_name( ).

      DATA lv_result type c length 200.

      CALL function 'RFC_SYSTEM_INFO'
      destination lv_destination
        IMPORTING
          RFCSI_EXPORT      = lv_result.

        out->write( lv_result ).
    catch cx_root into data(lx_root).
      out->write( lx_root->get_text( ) ).
    endtry.
  ENDMETHOD.

ENDCLASS.
Log on to answer question
Step 15: Test the class
  1. Save and activate the class (**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.

Log on to answer question
Step 16: Test yourself
In the ABAP class, what entity does the i_service_instance_name point to? Choose only one answer.
×
Step 17: Add error handling to the class for the RFC connection
  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
Log on to answer question

Next Steps

Prerequisites

Back to top