Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
pooja_tiwari3
Participant
Dear All,

 

This blog contains details about SAP ARIBA integration with 3rd party application to fetch ‘Printing Label data’ for ASN(Advanced Ship Notice) created in ARIBA.

Here we have SAP CIG and SAP Cloud Integration (formerly CPI) as middleware for this integration.

This integration gives a little bit of background ARIBA and CIG and integration flow design in CPI to achieve this requirement.

ARIBA Network-

Ariba Network is a dynamic, digital marketplace where buyers and suppliers collaborate on procurement and supply chain transactions. Ariba Network connects leading global organizations with their trading partners and provides a broad-based platform for all key business collaboration needs. It supports everything from trading partner discovery and e-procurement to e-invoicing and working capital management, allowing participants to buy, sell, and manage cash rapidly and effectively.


Cloud Integration Gateway-

The SAP Ariba Cloud Integration Gateway enables you to integrate a single or multiple SAP ERP or SAP S/4HANA systems with Ariba Network to efficiently manage supplier interactions across the spend management lifecycle. This can be done using SAP Ariba Cloud Integration Gateway or by using any middleware along with it to route messages to and from SAP Ariba Cloud Integration Gateway.

Requirement- Here the requirement is that once the supplier creates the ASN in Ariba portal ,they need the packing slip for all the packages which need shipping.

Hence once ASN is created in ARIBA portal, that is redirected to CIG system which then sends the ASN data in cXML format to SAP CI ( CPI). once CPI receives the cXML from CIG, it then converts the cXML to json format and sends it to 3rd party which will validate the ASN data and in case of success, it will return the ‘Printing label data in Base64 encoded format for pdf/png/jpg etc. formats’.

When CPI receives the label data, it then creates the cXML which needs to be sent back to CIG along with label data in form of attachments as MIME data.

And in case of any failure at 3rd party or at any other level, CPI triggers an exception handling call which will send only the cXML back to CIG with error code captured.

 


Technical Design of Iflow – In the flow design, we will be validating 1st if we are getting the data in the cXML received or not.if received then it will be processed further otherwise it will be discarded at the initial stage.

Once the proper data is received, will be converted to JSON format according to requirement and send to 3rd party for label generation.once lable data is sent back to CPI, its then saved in CPI in Content modifier properties and used at later stage.

After saving the label data, cXML which is required to send back to CIG will be created in message mapping where “To and from id” will be switched (which is received from CIG) and then the comment section will be added for attachment name.

Here we will be splitting label data using Splitter into 1 by 1 in case of multiple Label received.

And same will be sent along with cXML as MIME part data to CIG.

The integration flow design is like the below:


 

Step 1- Content modifier-To store the received cXML data and messageprocessinglogid.

 


Step2 – GET - to fetch the 3rd party Token from datastore (already fetch and stored in Data store) to authenticate the API while sending cXML data in JSON format.


Step3- Content modifier- To store token fetch from the previous step as header.


Step 4 - Content modifier- To pass the cxml as body to next step.


Step 5- message mapping- do the mapping as per requirement from cXML to 3rd party JSON structure.

Step6- xml to josn converter

Step 7 -groovy script – to replace all blank fields like “ “ with null.

def Message processData(Message message) {
def body = message.getBody(String) as String;
message.setBody(body.replaceAll('""',"null"));
return message;
}

Step 8 - Content modifier-to create a header with Authorization/Content-Type before making call to 3rd party API via http adaptor



Step 9- request Reply- make call to 3rd party API

Step 10- Json to XML converter.

Step 11- Message Mapping- to get the Label data in one place and ignore all the remaining fields.

Step 12- General Splitter- to split the xml into single Label containing xml.

 


Step 13- Content modifier-to store the xml generated from the previous step as header to be used later.


Step 14- Content modifier-To pass received cXML as body to next step which was stored in header in step 1


Step15 - Message Mapping- here we will map the received cXML with cXML which we need to send back with few minor details like , switch the sender and received from original cXML,pass ASN no as ASN_NO<currentDate>_Label .add attachment name in Comment section .remaining fields will be mapped as it is one to one.

 

URL--à   cid:part.example

 

Please note that if  URL details are not available in the cXML then Attachment sent will not be visible in ARIBA portal.


Step 16- Content modifier-To save the cXML created as header for further use.


Step 17- Content modifier- to fetch response body and pass it as main body for next step to fetch label data after general splitter step which was stored as header in Content Modifier12.


response xml as property to createMIME part in next step


 

 

Step 18- Content modifier- to fetch label and mime data from



 

Step 19- Content modifier- this is a very important step.here we will create message body to send to CIG

 

--MIME

Content-Type: text/xml; charset=UTF-8

${header.switchedxml001}

< 1 line left intentionally>

--MIME

Content-Type: ${property.type1};

Content-transfer-encoding: base64

Content-ID: <part1.example>

Content-Disposition: form-data; filename="attachment1.${property.ext1}"

< 1 line left intentionally>

${property.section1}

< 1 line left intentionally>

--MIME—

 

 


And Content type header is created to pass to CIG.


Step20 -21-> groovy script- After message mapping there is name space was added in cXML hence we are using groovy script to remove those extra details.




def Message processData(Message message) {
def body = message.getBody(String) as String;
message.setBody(body.replaceAll('<xml:cXML xmlns:xml="http://www.w3.org/XML/1998/namespace"','<cXML '));
/*message.setBody(body.replaceAll('</xml:cXML>','</cXML>'));*/

return message;
}




def Message processData(Message message) {
def body = message.getBody(String) as String;
message.setBody(body.replaceAll('<xml:cXML xmlns:xml="http://www.w3.org/XML/1998/namespace"','<cXML '));
/*message.setBody(body.replaceAll('<xml:cXML>','<cXML>'));*/

return message;
}




 

 

Step 22-> request reply - > Call CIG api to send this cXML along with MIME part which was created in step 19.

Step 23-> end- CIG will send 201 acknowledged payload for successful connection and ASN reception.

Exception Handling in case of Label data was not received from 3rd party- '


There can be many cases when suppliers sends wrong information like a past date for shipment or delivery or many other scenarios and in those cases Label data will not be sent from 3rd party , instead, it will fail and give the error code like 424,404,402 etc along with failure details.

Those details should also send back to CIG so that supplier will be notified that ASN created by him/her is incorrect and these are the error details.

Those things are taken care in exception handling

Step EX1 –Groovy Script-> here we will be fetching the http_code, http_error,http_message which we receive in case of wrong input sent to 3rd party and they send back the error details.




 

import com.sap.gateway.ip.core.customdev.util.Message;

 

def Message processData(Message message) {

 

// get a map of properties

def map = message.getProperties();

 

// get an exception java class instance

def ex = map.get("CamelExceptionCaught");

if (ex!=null) {

 

// an http adapter throws an instance of org.apache.camel.component.ahc.AhcOperationFailedException

if (ex.getClass().getCanonicalName().equals("org.apache.camel.component.ahc.AhcOperationFailedException")) {

 

// save the http error response as a message attachment

def messageLog = messageLogFactory.getMessageLog(message);

messageLog.addAttachmentAsString("http.ResponseBody", ex.getResponseBody(), "text/plain");

 

// copy the http error response to an exchange property

message.setProperty("http.ResponseBody",ex.getResponseBody());

 

// copy the http error response to the message body

message.setBody(ex.getResponseBody());

 

// copy the value of http error code (i.e. 500) to a property

message.setProperty("http.StatusCode",ex.getStatusCode());

 

// copy the value of http error text (i.e. "Internal Server Error") to a property

message.setProperty("http.StatusText",ex.getStatusText());

 

}

}

 

return message;

}

 




 

Step ex2- once the http_errobody is set as property by Groovy script ,we fetch that as another propert.


Step ex3 -Content Modifier- here we fetch the actual cXML received in Step 1 of main process.


Step ex4- Message Mapping- here we create receiver cXML from the Original cXML like step 15 with small change in ASN_no_<currentDate>_Error to indicate that this ASN has failed.

And URLà cid:error.example


Step ex5- Content Modifier- store the cXML created as header and error_body which we fetch from Groovy script in step ex1 as main body for next step


Step ex 6- Base 64 encoder- Encode the message received from 3rd party to pass as MIME part in later stage.

 

Step ex7- content Modifier- save the encoded message as header in this step.


And important part is creating the message body with all the information we fetched till now:

--MIME

Content-Type: text/xml; charset=UTF-8

<1 line left intentionally>

${header.errorcxmlbody}

<1 line left intentionally>

--MIME

Content-Type: text/plain;

Content-transfer-encoding: base64

Content-ID: <error.example>

Content-Disposition: attachment; filename=error.txt

<1 line left intentionally>

${header.encod}

<1 line left intentionally>

--MIME--


Step ex 8-9->same as step 20-21 , removing extra details from final file.

Step 10- create “Content-Type” header before calling CIG api.


Step 11- call CPI API.

End- CIG will respond with an Acknowledged message”.

 

Successful processing->


when the cXML is successfully processed in CPI and Label is returned from 3rd party which is then sent to ARIBA network successfully, you can see the attachment as pdf/png/jpg (which ever is applicable) in ARIBA network.
check the ASN name passed from ARIBA to CPI and then CPI to ARIBA back.







Failure in case of incorrect data ->


In case of failure to generate Label at 3rd party, exception process will trigger and ASNwith Error attachment is sent back to ARIBA.





 

Conclusion-

With this approach we can send the attachment to CIG/ARIBA network in successful and failure scenario both.

 

Reference

 

 

Happy Learnings

Pooja Tiwari

 
Labels in this area