SAP XI/PI/PO – End-to-End Synchronous Interface Development – Exposing RFC as REST API

This comprehensive tutorial will walk you through the process of exposing RFC as REST API in SAP PI/PO by creating a synchronous interface from the ground up. As soon as we receive a request through the REST API, we execute the RFC in the SAP ECC backend system to obtain the response, which is then sent back to the REST Client via the same synchronous communication.

Note: We will be using the standard RFC “BAPI_CUSTOMER_GETDETAIL2” for learning purposes. This RFC would retrieve customer details upon passing a customer code.

Here is a summary of the material we will cover in this tutorial:

Import RFC into PI from the ECC system to create mapping and interface objects in ESR.

To capture the customer code in the mapping and route it to the imported RFC, use a UDF.

Create RFC channels for the sender and the recipient.

Operation mapping is imported to create an Integrated Configuration.

In POSTMAN testing

Diagram of the Scenario:

The process flow is well addressed by the above graphic. To put it simply, the REST API will accept customer IDs in JSON format. Once we receive the JSON format, we will convert them to XML, map them to BAPI in RFC, and then execute the BAPI to the ECC system via the RFC channel. Following the execution of the BAPI, we will obtain customer data in an XML format in the response, which we will then transmit back to the originating system—in this example, POSTMAN.

Objects to be created in ESR:

Object TypeObject Name
Data TypeDT_REQ
DT_RESP
Message TypeMT_REQ
MT_RESP
Service InterfaceSI_SYNC_REQ_RESP_CustomerDetails_Out
Message MappingMM_REQ_CustomerID_2_BAPI_Request
MM_RESP_BAPI_Response_2_CustomerDetails
Operation MappingOM_REQ_RESP_Sync
ECC BAPIBAPI_CUSTOMER_GETDETAIL2
REST API URLhttp://<host>:<port>/RESTAdapter/custDetails/8321

1) Data Type

Request Data type

Response Data type

2) Message type

Request Message Type

Response Message Type

3) Service Interface – Outbound

4) Importing RFC into PI

The following actions must be completed in order to import RFC into PI:

a. Select EDIT MODE -> Double-click the relevant Software component version. After checking the OBJECTS ARE MODIFIABLE box, complete the ECC system information.

  • Name of System
  • Customer
  • Instant Messaging

b. A pop-up window will appear; right-click on “IMPORTED OBJECTS” and select “IMPORT SAP OBJECTS.”

c. Enter the ECC system’s logon credentials in the pop-up window.

  • server application
  • System identification
  • Login
  • Password (must input the ECC credentials where BAPI is located; not the PI credentials)

d. After logging in successfully, click the RFC, look for the necessary BAPI, and then click Proceed to complete the process.

e. Remember to ACTIVATE after import.

5) Message Mapping

We will be selecting the source message as Request Message type and the target message to RFC_Request.

We will be mapping the customer code which is passed in REST URL to PI through dynamic configuration. Hence, we need to create UDF.

In the graphical mapping view area, click on note like icon (left bottom corner) to create a UDF with 2 arguments.

Add the below code.

String custId = "";
try {
// get the dynamic configuration instance
DynamicConfiguration config = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

// define key to read from the dynamic configuration
DynamicConfigurationKey key1 = DynamicConfigurationKey.create(namespace,keyName);

// Read filename parameter from dynamic configuration based on the key
custId = config.get(key1);

}catch(Exception ee){}
return custId;

NOTE: This alone won’t work, we need to set customerID as REST ID in sender channel setup, which we will cover while setting up communication channels.

Map the company code to a constant or with company code value, if not mapped, while runtime system will throw error.

Response Message mapping:

We will be mapping BAPI response structure to response message type. Customer code will be a one to one mapping, customer name and address will be concatenation of NAME and NAME2, COUNTRY and CITY.

6) Operation Mapping

Source Operation – outbound service interface where we mapped request and response message types.

Target Operation – BAPI  RFC

Once BAPI and service interface selected, click on READ OPERATIONS button, to generate the request and response tab, where we can import the request and response message mapping.

Objects to be created in ID:

7) Sender communication channel – REST

TEST_CC_REST_SND_CustomerDetails

Select the message protocol to REST

General Tab:

As the input data is going to be in JSON format, we will be selecting Data format as JSON and select the checkbox “convert to xml”.

“Log JSON message” – For logging the payload in PI monitoring

“Add Wrapper Element” – Provide the request message type name and namespace. Once the JSON payload is converted to XML, wrapper element MESSAGE TYPE will get added to the outer layer.

Select the Quality of service to BEST EFFORT as it is a synchronous interface. For RESPONSE message format, XML can be selected or if the receiver end accepts only JSON, same can be selected.

Channel Selection tab:

In the channel selection tab, only detail we need to specify is the URL endpoint.

Tab for Restricted Resources:

Since we previously completed the dynamic configuration, we will be passing the client ID through it.The parameter name must be mentioned in the REST channel as well.

Tab for Rest Operation:

Leave the HTTP Operation alone.

Tab for operation determination:

This page is only relevant for sync interfaces, where it is necessary to provide information about the response interface, such as the service interface and operation that were carried out.

The operation variable name, which we must provide in the variable column, will be mentioned in the REST Operation tab.

The action taken will be expression.

The name of the service interface and the associated namespace are called the operation.

Rest of the two tabs is untouched.

8) Receiver communication channel – RFC

TEST_CC_RFC_RCV_CustomerDetails

In RFC receiver we need to specify the ECC system details:

  • RFC Server Type – SAP system
  • Application server
  • System number – 00
  • Authentication mode – Use logon data of SAP system
  • Logon user
  • Logon password
  • Logon language
  • Logon client

9) Integrated Configuration

Utilizing the operation mapping created in ESR, import the communication channel between the sender and the recipient.

To observe the version-specific payloads in the PI monitoring screen, navigate to the Advanced Settings tab, select Staging and Logging, and then select the USE SCENARIO-SPECIFIC CONFIGURATION option. From there, choose “Store” and “Log.”

10) Testing in POSTMAN

Verify the request and answer in ECC for the chosen BAPI before beginning the testing. Navigate to SE37 in the ECC system, type “BAPI_CUSTOMER_GETDETAIL2,” and then select Execute.

Response:

able to take a reply. We can proceed now.

*custDetails: The URL endpoint that we specified when configuring the REST SENDER CHANNEL.

*customerID: A customer code that we can supply so that the ECC can reply to it.

Copy this URL, then click POST.

Under the body, attach the below payload in JSON format.

{
    "CustomerID": 8321
}

Provide the PI username and password in the AUTH tab.

Click on SEND to see the response.

Just as that !!!. I hope that by reading this post, you gained some new knowledge. Watch this space for further videos and learning series on SAP XI/PI/PO that we will be providing in the near future.


YOU MAY BE INTERESTED IN

Tutorials on SAP ABAP

Is Python good for SAP?

  • Related Posts

    How to Create an Audio Video Multimedia Player in SAPUI5 (Advanced SAPUI5-23)

    The drab blue screen that most users detested was no longer a feature of SAP Reports & Outputs. Please do not misunderstand us. Although end users were never satisfied, even…

    How to Install SAP Web IDE Personal Edition Step by Step

    Introduction Installing the Web IDE personal edition did not require the use of any additional guides. However, there isn’t a single online guide that explains how to get over every…

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You Missed

    SAP XI/PI/PO – End-to-End Synchronous Interface Development – Exposing RFC as REST API

    • By Varad
    • January 18, 2025
    • 13 views
    SAP XI/PI/PO – End-to-End Synchronous Interface Development – Exposing RFC as REST API

    How to Create an Audio Video Multimedia Player in SAPUI5 (Advanced SAPUI5-23)

    • By Varad
    • January 17, 2025
    • 39 views
    How to Create an Audio Video Multimedia Player in SAPUI5 (Advanced SAPUI5-23)

    How to Install SAP Web IDE Personal Edition Step by Step

    • By Varad
    • January 16, 2025
    • 30 views
    How to Install SAP Web IDE Personal Edition Step by Step

    Advanced SAPUI5 Part-30: the Grid Table Advanced Features

    • By Varad
    • January 15, 2025
    • 33 views
    Advanced SAPUI5 Part-30: the Grid Table Advanced Features

    SAP GPS-like tool with Google Map API

    • By Varad
    • January 14, 2025
    • 33 views

    Accounting Record for Sales and Distribution

    • By Varad
    • January 13, 2025
    • 47 views
    Accounting Record for Sales and Distribution