Skip to Content

Call a Remote Function Module From ABAP Envionment

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

Call a Remote Function Module From ABAP Envionment

Requires Customer/Partner License

06/12/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: Check your SAP Cloud Connector configuration

First, in SAP Cloud Connector Overview, check your configuration:

Image depicting step1-check-scc

  • Leave the Location ID empty.
  • Note the technical name of the subaccount. You can find this by choosing your SAP Cloud Platform, NEO, subaccount in SAP Cloud Cockpit and choosing the information (i) icon.

Image depicting step1b-neo-tech-name

Log on to answer question
Step 2: Specify the remote function module

Now, still in the Cloud Connector, enter the resource you need, RFC_SYSTEM_INFO.

  1. In your subaccount, choose Cloud to On-Premise > Access Control.

  2. Check the Mapping Virtual to Internal System. You will need the SID and port later.

    Image depicting step1a-scc-resources-sid
  3. Add the resource RFC_SYSTEM_INFO by choosing +.

    Image depicting step1d-new-rfc
  4. Enter the name of the RFC, e.g. RFC_SYSTEM_INFO and choose Save.

    Image depicting step1e-name-rfc

The RFC appears in the list of resources.

Log on to answer question
Step 3: 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 4: Create a new HTTP destination for the destination service instance
  1. In the Destination Configuration pane, enter the following values:

    • Name, e.g. : S4HTEST_HTTP_XXX (You should include the suffix HTTP and replace XXX with your initials or group number.)
    • Type: HTTP
    • Description, e.g. Test S4H HTTP connection
    • URL: http://<SID>:51080/sap/bc/ping - where SID = the System ID of your on-premise ABAP System
    • OnPremise
    • BasicAuthentication
    • User: Your user for the on-premise ABAP system
    • Password: Your password
    The IP address and port must be the one you specified in the Cloud Connector earlier.
  2. Choose Save.

The destination appears in the list.

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. : S4HTEST_RFC_XXX (You should include the suffix RFC and use the same prefix as for your HTTP connection)
    • Type: RFC
    • Description, e.g. Test S4H RFC connection
    • Location ID: blank
    • User: Your user
    • Password: Your password
  2. Add the following additional properties and values, by choosing New Property:

    • jco.client.ashost = <Your SID> - again, the System ID of your on-premise ABAP System in lower-case
    • jco.client.client = <Your ABAP System client, e.g. 100
    • jco.client.sysnr = <Your ABAP System number>, e.g. 10
Log on to answer question
Step 6: Create a Communication System for SAP Cloud Connector
  1. Again, in the Dashboard, choose Communication Systems > New.

  2. Enter the credentials for an administration user for your SAP CP Neo account:

    • Host name

      Image depicting step8b-comm-system-1
    • Administration 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 Z_...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_SERVICE_INSTANCE_NAME = 'OutboundComm_for_RFCDemo_XXX'
                             I_NAME                  = 'S4TEST_RFC_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).

  3. Replace the i_name with your the name of the specific RFC destination (which you created in SAP Cloud Cockpit in the tutorial Create a Communication Arrangement for Outbound Communication).

    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 Z_A4C_RFC_XXX definition
  public
  final
  create public .

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



CLASS Z_A4C_RFC_XXX IMPLEMENTATION.
  METHOD IF_OO_ADT_CLASSRUN~MAIN.
    TRY.
      DATA(lo_destination) = cl_rfc_destination_provider=>CREATE_BY_CLOUD_DESTINATION(
                               I_SERVICE_INSTANCE_NAME = 'OutboundComm_for_RFCDemo_XXX'
                               I_NAME                  = 'S4TEST_RFC_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: Optional: Create an ABAP class for the HTTP connection

This class allows you to troubleshoot the RFC connection by checking that the HTTP connection works.

class Z_A4C_HTTP_TEST_XXX definition
  public
  final
  create public .

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

CLASS Z_A4C_HTTP_TEST_XXX IMPLEMENTATION.
  METHOD IF_OO_ADT_CLASSRUN~MAIN.
    TRY.
        DATA(lo_destination) = cl_http_destination_provider=>create_by_cloud_destination(
          i_name                  = 'S4HTEST_HTTP_XXX'
          i_service_instance_name = 'OutboundComm_for_RFCDemo_XXX'
          i_authn_mode = if_a4c_cp_service=>service_specific ).

        DATA(lo_http_client) = cl_web_http_client_manager=>create_by_http_destination( i_destination = lo_destination ).
        DATA(lo_request) = lo_http_client->get_http_request( ).
        DATA(lo_response) = lo_http_client->execute( i_method = if_web_http_client=>get ).
          out->write( lo_response->get_status( ) ).
          out->write( lo_response->get_text( ) ).

      CATCH cx_root INTO DATA(lx_exception).
        out->write( lo_response->get_status( ) ).
        out->write( lx_exception->get_text( ) ).
    ENDTRY.

  endmethod.
ENDCLASS.

Log on to answer question
Step 18: 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