Wednesday, 12 January 2022

BTP Integration – Process email Attachment to Post Deep insert using odata on Premise ECC

There are different integration scenarios where we would like send to an email with attachment of contents (XML or json) which can be read and sent to ECC to post a transaction identified by the integration. To achieve this we have to perform the following Steps

1. Configure ECC and cloud connector for http

2. check connectivity for IMAP download and import the certificates into Integration Suite key Store

3. Create the BTP Integration iflow to process inbound email to read the attachment and invoke the configured odata service and send result email or exception process email

4. Test the end to end process

We describe in detail each of these in derail

1. Configure cloud connector for the on Premise ECC system as shown below ( cloud to on Premise or your subaccount )

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

Make sure the connection works

2. Check in Integration suite Operations View Connectivity test for IMAP for the email provider as shown below – I have created a folder CPI in my yahoo account to which I will move the emails with attachments of XML odata to create deep insert for Sales Order 

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

Download the Certificates and import all the certificate files into the key store in the Operations View.

3. Create the iflow which will read the inbound email with attachment – Using the groovy script read the attachment and transfer to message body (XM). The odata service have chosen for this blog is http://s4h2:80001/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/SalesOrderSet. This involves a deep insert consisting of Sales Order header and items. The Iflow consists of main process and exception sub process the result sent to email as shown below

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

We will show the settings for each of the components below                                                        

3A) inbound email settings 

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

3B) Odata Adapter Settings as as shown below

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

3c) Main odata POST process response outbound email configuration is as shown below 

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

3D) include an Exception sub process – Add a content Modifier with body showing the exception message and connect the email to email. For this integration I have copied the same the same email settings and changed the title to indicate exception. The Content Modifier settings are as shown 

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

Save and deploy the flow

4. Test the filow                                                                                                                 

4A) Once the iflow is deployed we need to test end to end for successful post to validate the main process; To do this first we have to create XML data so that the format matches the metadata for SalesOrderSet of the odata service.. This is as shown bleow

<SalesOrderSet>
<SalesOrder>
<SalesOrderID></SalesOrderID>
<Note>EPM DG: SO ID SAP CPI Blog Test</Note>
<NoteLanguage>EN</NoteLanguage>
<CustomerID>0100000000</CustomerID>
<CustomerName>SAP</CustomerName>
<CurrencyCode>USD</CurrencyCode>
<GrossAmount>14385.85</GrossAmount>
<NetAmount>12088.95</NetAmount>
<TaxAmount>2296.90</TaxAmount>
<LifecycleStatus>C</LifecycleStatus>
<LifecycleStatusDescription>Closed</LifecycleStatusDescription>
<BillingStatus>P</BillingStatus>
<BillingStatusDescription>Paid</BillingStatusDescription>
<DeliveryStatus>I</DeliveryStatus>
<ToLineItems>
<SalesOrderLineItemSet>
<SalesOrderLineItem>
<SalesOrderID></SalesOrderID>
<ItemPosition>0000000010</ItemPosition>
<ProductID>HT-1000</ProductID>
<Note>EPM DG: SO ID 0500000000 Item 0000000010</Note>
<NoteLanguage>EN</NoteLanguage>
<CurrencyCode>USD</CurrencyCode>
<GrossAmount>1137.64</GrossAmount>
<NetAmount>956.00</NetAmount>
<TaxAmount>181.64</TaxAmount>
<DeliveryDate>2022-01-8T23:30:10.231</DeliveryDate>
<Quantity>1</Quantity>
<QuantityUnit>EA</QuantityUnit>
</SalesOrderLineItem>
</SalesOrderLineItemSet>
</ToLineItems>
</SalesOrder>
</SalesOrderSet>

Save a file with the above consents and send this file as an attachment to the email address configured in the inbound email settings in the iflow. Once the email is received in your inbox move it to the CPI folder ( or the folder you have configured in the inbound email processing settings). Recollect that we have set the scheduler to poll the folder every minute – the file will be picked up and contents transferred to the body of the message which is then passed to odata payload to make a deep insert to post sales order. The Status and response is sent to by emaill configured in the outbound email The response email is as shown below

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

4B) Exception sub process email To test this we change url port to 8001 and redeploy and repeat the process of sending the email attachment and copy to the CPI folder that we configured in the inbound email processing We now get an exception email as shown below

SAP BTP Integration, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Certification, SAP ABAP Guides, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Process

We have seen how we can process inbound email attachment – transfer the attachment contents to message body and send this to odata adapter to invoke on Premise ECC odata service to perform deep insert and then send the response or exception to the configured email address in the outbound email configuration.

Source: sap.com

No comments:

Post a Comment