This blog post is intended to inform readers about a recent objective task I encountered while working on a project that involved two SAP systems. The purchase order number validation in both systems in the SAP CPI environment had to be done. If the two PO numbers were the same and confirmed, then inbound scenario has to be triggered.
System 1 : SAP S4 Hana (Note we will be using HTTPS considering it as SAP System)
System 2 : SAP ByD
Below is the list of Contents :
- Pre-requisites
- Process Flow
- iflow Development
- Exception Handling
————————————————————————————————————————————–
1. Pre-requisites
- In order to create this scenario work you will need access to SAP BTP (Integration Suite) with necessary roles and capabilities assigned. Or else you can refer this blog to Set Up Integration Suite
- Have knowledge about creating Integration flows (iflow) using SAP CPI.
- Knowledge of Adapters and other CPI Pallet options.
- OData API, Mail Credentials (for Exception).
- Proxy, RFC, IDoc (As we are involving two system SAP & ByD therefore for posting data from SAP to CPI we can do it using the three given options) *Here we are using HTTPS considering it as a SAP System.
'
2. Process Flow
Process Flow
3. iFlow Development
Create a Package and iflow
Fill up Package Name of your choice, Technical Name and Description about the scenario.
Now Create new iflow and fill up details such as name, id and description.
After Clicking on "Ok"
As per our Flow Diagram first step is to
Fetch SAP Data into CPI (Content Modifier)
Postman As SAP System (System A)
Now we will use
"Content Enricher" (To know functioning of
https://help.sap.com/docs/cloud-integration/sap-cloud-integration/define-content-enricher )
In the 2nd Step we will connect another system (ByD) using OData to "Content Enricher" to merge the payloads from both systems.
OData Configuration :
In the Processing Tab select the fields you want in your payload structure.
Now till this step the message payload could look somewhat like this :
<?xml version='1.0' encoding='UTF-8'?>
<multimap:Messages xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge">
<multimap:Message1> //Message from System A (Which is SAP in our Case)
<DocNumber>100</DocNumber>
<PurchaseOrderNumber>12345</PurchaseOrderNumber> //This is the Purchase order number from SAP System
<Item>Television</Item>
</multimap:Message1>
<multimap:Message2> //Message from System B (Which is ByD in our Case)
<rfc:ZHR_GET_EMP_BENEFIT_DETAILS.Response xmlns:rfc="urn:sap-com:document:sap:rfc:functions">
<LT_0167>
<PONum>12345</PONum> //This is the Purchase order number from ByD System
<item>
<PERNR>00012345</PERNR></item>
<DOB>01/01/2020</DOB>
....
</LT_0167>
</rfc:ZHR_GET_EMP_BENEFIT_DETAILS.Response>
</multimap:Message2>
</multimap:Messages>
<multimap:Message1> Payload from System A is captured in </multimap:Message1>
<multimap:Message2> Payload from System B is captured in </multimap:Message2>
Now in the next step we will use XPATH in content modifier.
Source Value is captured from the XML Payload
Eg. <Parent>
<Items>
<material>101213</material>
<price>100.00</price>
</Items>
</Parent>
If we want to pick only price then the source value would be.
//Parent/Items/price
In the same way select source values of both PO Numbers according to the combined payload.
Now we will use XSLT Mapping Option from Pallets.
and write the below code to compare two nodes together. (Our Logic)
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" omit-xml-declaration="no" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<Output>
<xsl:apply-templates select="/ParentNode/Child/PONum = /ParentNode_ByD/Child/ID"/>
</Output>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:select-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:transform>
You can notice in the <Output> </Output> Node i have compared the Xpaths which we have stored in Content Modifier in the previous step.
It will ultimately compare both nodes dynamically and give output in the form of Boolean (True or False)
Till this step our development is able to understand whether the XML Nodes are matching or not.
Now we will be using
"Router" to bifurcate the flow.
- Router will have two branches (Matching & Not Matching)
If both the nodes are same the iflow must return a message displaying that both ID's are same and proceed to next scenario.
And in last we will be using Process Direct Adapter to trigger next scenario.
--------------------------------------------------------------------------------------------
* If Nodes are not equal then user should get a mail that the iflow has failed.
To make this happen.
This step is same as in the Success Node.
Now to get a detailed error description we will use groovy script.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String;
def messageLog = messageLogFactory.getMessageLog(message);
if(messageLog != null){
messageLog.setStringProperty("Logging#1", "Printing Payload As Attachment")
messageLog.addAttachmentAsString("ResponsePayload:", body, "text/plain");
}
return message;
}
And to Connect the End with Receiver using Mail
How to Configure Mail Adapter
Save & Deploy the Scenario and test it with Postman.