Note: For learning reason, we will utilize a standard RFC “BAPI_CUSTOMER_GETDETAIL2”, which would return client subtleties on passing client code. Now let’s learn SAP XI/PI/PO – Exposing RFC as REST API in SAP XI/PI/PO – Synchronous Interface Development End to End blog.
In short, below is the content we will be elaborate in this tutorial: SAP XI/PI/PO – Exposing RFC as REST API in SAP XI/PI/PO – Synchronous Interface Development End to End
- Create mapping and interface objects in ESR by importing RFC into PI from ECC system.
- Create UDF for capturing the customer code in the mapping and route it to imported RFC.
- Create sender REST and receiver RFC channel.
- Create Integrated Configuration by importing operation mapping.
- Testing in POSTMAN
Scenario Diagram:
Above outline is adequate to address the interaction stream. In straightforward terms, REST Programming interface will acknowledge client ID (in JSON design), when we get it in JSON design we will change it into XML and map it over completely to BAPI in RFC and will execute BAPI by means of RFC channel to ECC framework. When BAPI executed, in the reaction we will get client subtleties (in XML design) and send back to source framework (for this situation, Mailman).
Objects to be created in ESR: SAP XI/PI/PO – Exposing RFC as REST API in SAP XI/PI/PO – Synchronous Interface Development End to End
Object Type | Object Name |
Data Type | DT_REQ DT_RESP |
Message Type | MT_REQ MT_RESP |
Service Interface | SI_SYNC_REQ_RESP_CustomerDetails_Out |
Message Mapping | MM_REQ_CustomerID_2_BAPI_Request MM_RESP_BAPI_Response_2_CustomerDetails |
Operation Mapping | OM_REQ_RESP_Sync |
ECC BAPI | BAPI_CUSTOMER_GETDETAIL2 |
REST API URL | http://<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
For bringing RFC into PI, underneath steps should be dealt with:
a. Double tap on the relating Programming part form – > Alter MODE – > Select the Items ARE MODIFIABLE checkbox and finish up the ECC framework subtleties.
- System Name
- Client
- Message Server
b. Right snap on the “IMPORTED Items” and snap on “IMPORT SAP Articles”, which will hurl a pop.
c. In the pop-up enter the logon information of ECC system.
- Application server
- System number
- Username
- Password (Not PI credentials, need to enter the ECC credentials where BAPI is residing)
d. Once effectively signed on, click on the RFC and look for the expected BAPI and click on Proceed and wrap up.
e. Once imported, don’t forget to ACTIVATE.
5) Message Mapping
We will choose the source message as Solicitation Message type and the objective message to RFC_Request.
We will plan the client code which is passed in REST URL to PI through unique arrangement. Consequently, we want to make UDF.
In the graphical planning view region, click on note like symbol (left base corner) to make a UDF with 2 contentions.
Add the beneath 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;
Presently map the two constants like beneath, that we added as contentions in UDF.
Input parameter 1 – CustomerID
Input parameter 2 – http://sap.com/xi/XI/System/REST
Map the UDF to client ID target hub. Thus, while runtime, the client ID in the REST URL gets relegated to target hub through unique arrangement which we finished at this point.
NOTE: This by itself won’t work, we really want to set customerID as REST ID in shipper channel arrangement, which we will cover while setting up correspondence channels.
Map the organization code to a steady or with organization code esteem, on the off chance that not planned, while runtime framework will toss mistake.
Reaction Message planning:
We will plan BAPI reaction construction to reaction message type. Client code will be a coordinated planning, client name and address will be link of NAME and NAME2, Nation and CITY.
6) Operation Mapping
Source Activity – outbound help interface where we planned solicitation and reaction message types.
Target Activity – BAPI RFC
When BAPI and administration interface chose, click on READ Tasks button, to produce the solicitation and reaction tab, where we can import the solicitation and reaction message planning.
Objects to be created in ID:
7) Sender communication channel – REST
TEST_CC_REST_SND_CustomerDetails
Select the message convention to REST
General Tab:
As the information will be in JSON design, we will choose Information design as JSON and select the checkbox “convert to xml”.
“Log JSON message” – For logging the payload in PI checking
“Add Covering Component” – Give the solicitation message type name and namespace. When the JSON payload is switched over completely to XML, covering component MESSAGE TYPE will get added to the external layer.
Select the Nature of administration to BEST Exertion as it is a simultaneous connection point. For Reaction message design, XML can be chosen or on the other hand assuming that the recipient end acknowledges just JSON, same can be chosen.
Channel Choice tab:
In the channel choice tab, just detail we really want to determine is the URL endpoint.
This is the endpoint which will appear after .. http://<host>:<port>/RESTAdapter/custDetails
Rest Assets tab:
Since we will pass the client ID through unique setup, which we did prior. We additionally need to specify the boundary name in REST channel.
Rest Activity tab:
Leave it for all intents and purposes – HTTP Activity
Activity assurance tab:
This tab is pertinent just for sync interfaces, where we really want to specify the reaction interface subtleties, as through which administration connection point and activity performed.
In the REST Activity tab, activity variable name will be referenced, which we should determine in factor segment.
Articulation will be the activity performed.
Activity is the help interface name and its comparing namespace.
Rest of the two tabs is immaculate.
8) Receiver communication channel – RFC
TEST_CC_RFC_RCV_CustomerDetails
In RFC beneficiary we want to determine the ECC framework subtleties:
- 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
Import the Source and collector correspondence channel with the activity planning created in ESR.
In the high level settings tab, under Arranging and Logging, select the Utilization Situation Explicit Design and select “Store” and “Log” choice inorder to see the adaptation wise payloads in the PI observing screen.
10) Testing in POSTMAN
Prior to beginning the testing, check the solicitation and reaction in ECC for the BAPI we chose. In ECC framework, go to SE37 – > Enter “BAPI_CUSTOMER_GETDETAIL2” and tap on execute.
Response:
Ready to get reaction. We are all set.
First create the REST Programming interface URL:
*custDetails – URL endpoint we gave in REST Source CHANNEL design.
*customerID – client code which we can accommodate which the ECC can send reaction.
Glue this URL and select POST.
Under the body, attach the below payload in JSON format.
{
"CustomerID": 8321
}
Give the PI username and secret key in the AUTH tab.
Click on SEND to see the response.
Really that straightforward !!!. Trust you gained some new useful knowledge by following this post. We will be sharing more instructional exercises and learning series on SAP XI/PI/PO, so pay special attention to our future materials.
YOU MAY LIKE THIS
Future of APIs in SAP: Gazing into the Crystal Ball
Consuming APIs in SAP Applications
SAP Solutions for the Healthcare Sector: Transforming Patient Care
Transforming the Manufacturing Industry with SAP: A Comprehensive Guide