SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

How to migrate RFC Lookups from SAP Process Orchestration to Cloud Integration

This tutorial explores two different solutions to implement RFC Lookup using the Cloud Integration capability of the SAP Integration Suite.

Overview

🎓 intermediate 60 min. SAP Integration SuiteCloud IntegrationSAP Process IntegrationSAP Process OrchestrationIntermediate

You will learn

  • How to implement RFC Lookup on Cloud Integration using Groovy Script and UDF (User-Defined Function) on Message Mapping.
Rafaela Nunes R Rafaela Nunes August 14, 2024
Created by August 6, 2024
Contributors

Prerequisites

Prerequisites

  • Ensure that the function module is available in your SAP system.

Steps

Intro

In SAP Process Orchestration, a Remote Function Call (RFC) Lookup is a feature that enables communication between different systems or components within the SAP landscape and it is used during the execution of a mapping program. The SAP Java Connector (SAP JCo) is a development library that enables a Java application to communicate with SAP systems using SAP’s RFC protocol and it will be used in both solutions. For more information refer to the SAP Java Connector.

Step 1 Use Case 1 - Implement RFC Calls in Cloud Integration Using Groovy Script

The first approach can be done by using a Groovy Script on Integration Flow. This Script dynamically retrieves the RFC destination and RFC names from the properties, sets the RFC Request fields parameters from properties, executes the RFC call, and converts the response into XML format.

Using a Groovy Script provides flexibility in implementation by allowing dynamic adjustment of import parameters based on exchange properties in the Integration Flow. This capability allows developers to adapt to many different RFC scenarios without change the Groovy Script. However, this Groovy Script just execute a single RFC call per call, so any need for executing multiple RFC calls would require changes to the code.

The implementation of this solution can be done by following the next steps:

  1. Create an Integration Flow on Cloud Integration.

  2. Add a content modifier called “Set Properties & RFC Fields” to define the following Exchange Properties:

    image1
    image1

    • RFCDestination: name of the RFC Destination you will use. (For more information refer to the: Create RFC Destinations).

    In this tutorial, the solution was implemented using the BAPI_FLIGHT_CHECKAVAILABILITY RFC. Feel free to adjust the properties according to your specific requirements.

    • RFCName: Name of the RFC you will use.
    • payload: After the request-reply step, it is necessary to retrieve the original incoming message. This step ensures that subsequent operations have access to the initial data. You can achieve this by using ${in.body}.
    • InputParameter_*: This is the prefix for the name of the RFC Request field. Each property should start with this prefix followed by the specific name of the RFC Request field. For each property, specify the XPath of the corresponding field to map from the source structure of the message mapping.

    image2
    image2

    Note: You can add or remove properties as needed.

  3. Create a new Groovy Script in the Integration Flow and paste the code below or import the following Groovy Script on the References.

    image3
    image3

    The runRFC Groovy Script is the following:

    Groovy
        import com.sap.gateway.ip.core.customdev.util.Message
        import com.sap.conn.jco.*
    
        def Message processRFCCall(Message message) {
            def destinationName = message.getProperty("RFCDestination")
            def rfcName = message.getProperty("RFCName")
    
            try {
    
                JCoDestination jcoDestination = JCoDestinationManager.getDestination(destinationName)
                JCoFunction function = jcoDestination.getRepository().getFunction(rfcName)
    
                if (function != null) {
                    def parameterList = function.getImportParameterList()
    
                    message.getProperties().each { key, value ->
                        if (key.startsWith("InputParameter_")) {
                            def paramName = key.substring("InputParameter_".length())
                            try {
                                parameterList.setValue(paramName, value)
                            } catch (Exception e) {
                                throw new Exception("Error setting parameter '${paramName}': ${e.getMessage()}")
                            }
                        }
                    }
    
                    function.execute(jcoDestination)
    
                    def result = function.toXML()
                    message.setBody(result)
                } else {
                    throw new Exception("ERROR: RFC function '${rfcName}' not found")
                }
    
            } catch (JCoException e) {
                throw new Exception("ERROR executing RFC function: ${e.getMessage()}")
            } catch (Exception e) {
                throw new Exception("Unexpected error: ${e.getMessage()}")
            }
    
            return message
        }
  4. Define a content modifier called ‘RFC Response Fields’ to capture and store the values of response fields extracted from the RFC.

    image4
    image4

  5. Add exchange properties (as needed) and specify the XPath of the RFC response fields.

    image5
    image5

    Note: You can add or remove properties as needed.

  6. Create a message mapping by adding the source and target messages previously imported in the ‘References’ section of the Integration Flow.

    image5
    image5

  7. In this example, the source message is ‘flightConnectionRequest’ and the target message is ‘flightConnectionResponse’. It was done a 1:1 mapping on the Connection node from ‘flightConnectionResponse’ and additionally, on the ‘Seats’ node, the ‘getProperty’ function was added, and a constant was defined using the output parameter from the previous step for the RFC response fields.

    image16
    image16

  8. Next, for the target fields required, add a constant and “getProperty” from the standard functions and enter the name of the Exchange Property defined in the previous step.

    image6
    image6

  9. Save the integration flow, deploy it, and trigger a message.

    image7
    image7

    The mapping result is the following:

    XML
        <?xml version="1.0" encoding="UTF-8"?>
            <ns0:flightConnectionResponse xmlns:ns0="http://pimas.com">
                <Connection>
                    <Airline>AA</Airline>
                    <Connection>0017</Connection>
                    <Date>20230921</Date>
                </Connection>
                <Seats>
                    <Economy>15</Economy>
                    <Business>0</Business>
                    <First>2</First>
                </Seats>
            </ns0:flightConnectionResponse>
Step 2 Use Case 2 - Implement RFC Calls in Cloud Integration Using a UDF on Message Mapping
+
Step 3 Use Case 3 - Implement Multiple RFC Calls in Cloud Integration Using UDF on a Single Message Mapping
+
Step 4 Test yourself
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 4
1. Use Case 1 - Implement RFC Calls in Cloud Integration Using Groovy Script 2. Use Case 2 - Implement RFC Calls in Cloud Integration Using a UDF on Message Mapping 3. Use Case 3 - Implement Multiple RFC Calls in Cloud Integration Using UDF on a Single Message Mapping 4. Test yourself

Learn more →