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: 
pkaushiksrinivas
Explorer
12,158

Introduction


This blog covers an idea on how we can put CPI Aggregator to use for clubbing payloads having a similar value and creating separate files for them.

As an example, we can take Customer Master payloads being triggered from SAP to CPI. All these messages may have different company codes, but output needs to be created in such a way that, separate files need to be created for each unique company code viz. All payloads having Company Code=A will be present in a file, al payloads having Company Code=B will be present in another file and so on.

Requirement :

  • Flow : SAP S4 --> CPI --> 3rd party system

  • Source Message : IDOC (multiple IDOCs sent in a single Batch)

  • Target Message : External Messgae

  • Customer Master IDOCs will be sent from S4 HANA to CPI

  • CPI will have to create a new file on 3rd party SFTP per unique Company Code (Messages having a particular Company Code will be clubbed together in one file)


Sample Input : 


Sample Input Having 2 unique Company Codes


Output Expected : 2 Files, one for 1156 Company Code and other for 1152 (As a Sample case, here Mail adapter is used instead of SFTP)

CPI iFlow Sample : 

To mock a scenario-Content Modifier holds the IDOC data here, post which individual IDOCs are split in a general splitter. IDOC-External definition mapping is done in next step and aggregated further.



CPI iFlow Sample with Aggregation Condition


Using an Aggregator pattern, we can collect and store individual messages until a complete set of related messages have been received. The aggregated message is then sent to the actual receiver (One message per unique value in Correlation Condition)

We use an Aggregator to group all messages related to a particular Company Code by giving the Correlation Expression. (In the image above, the XPath in Aggregator Correlation is taken from External message post mapping)

Output : 


Output showing 2 separate eMails received for each unique customer code


 

Pros : 

  • Instead of writing complex mappings to achieve the above requirement, Aggregator makes it easier to group the message based on Correlation condition


Cons :

  • Aggregator expects a waiting time, which means once data is received in an aggregator, it will wait for that amount of time after which it will send output to further steps.


Additional Observations :

Scenarios wherein grouping messages having a particular similar value like above is required, but instead of creating 2 separate files like above, only 1 file is required which contains data related to both company codes segregated within file at output, the use of Aggregator may have a limitation here.

However, would welcome integration experts to add observations and comments w.r.t the same.

Summary


The use of Aggregator in CPI with a simple use case was explained above.

Comments or feedback/suggestions, pros/cons with respect to the above are welcome from fellow Integration folks.

References :


5 Comments
Dagmar
Explorer
0 Kudos

Hello, thank you for sharing with us the case! I am new to the CPI.

I tried to do something similar, but I am struggling with a problem, thatafter aggregator, it stops. 

Like it never goes to an end. Also in the trace, I dont see the iflow reached end.

Is there any step after aggregator that I am missing please?

I have noticed, that in the data store, the agreggator is in status „Waiting“. I am not sure how to trigger it.

 

Thank you!

Dagmar

SantoshKabbur
Discoverer

Hi Dagmar,

just briefly i will explain the flow , how we can use tha aggregator function in sap cpi.

Corelated: It will mainly helpful for gathering the same correlated messages. the below highlighted message should be same to gather the message at output.

Aggregation Startergy

1)Algorithms: We can mention the output format whether it's sequence manner(ascending,descending,) or combine.

2)Last message: here we need to mention the xpath for the condition ex: /Order_MT/lastProd ='Yes'

3)CompletionTimeout: need to mention the time out frequency in minutes (till this frequency completion iflow will not give the response )

4)DataStore Name: as per your convince we can assign the datastore name

PFA for your reference

Sample Payload: (Message are sent one after the other to the iflow)

1.<Order_MT>
    <orderNumber>123</orderNumber>
    <prodID>1</prodID>
    <supplierName>Santosh</supplierName>
    <productName>Battery</productName>
    <lastProd>No</lastProd>
</Order_MT>
 
2.<Order_MT>
<orderNumber>123</orderNumber>
<prodID>2</prodID>
<supplierName>test2</supplierName>
<productName>test2</productName>
<lastProd>No</lastProd>
</Order_MT>
3.<Order_MT>
<orderNumber>123</orderNumber>
<prodID>3</prodID>
<supplierName>test3</supplierName>
<productName>test3</productName>
<lastProd>No</lastProd>
</Order_MT>
4.<Order_MT>
<orderNumber>123</orderNumber>
<prodID>4</prodID>
<supplierName>test4</supplierName>
<productName>test4</productName>
<lastProd>Yes</lastProd>
</Order_MT>
 
Output:
<multimap:Messages xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge">
<multimap:Message1>
<Order_MT>
<orderNumber>123</orderNumber>
<prodID>1</prodID>
<supplierName>test1</supplierName>
<productName>test1</productName>
<lastProd>No</lastProd>
</Order_MT>
<Order_MT>
<orderNumber>123</orderNumber>
<prodID>2</prodID>
<supplierName>test2</supplierName>
<productName>test2</productName>
<lastProd>No</lastProd>
</Order_MT>
<Order_MT>
<orderNumber>123</orderNumber>
<prodID>3</prodID>
<supplierName>test3</supplierName>
<productName>test3</productName>
<lastProd>No</lastProd>
</Order_MT>
<Order_MT>
<orderNumber>123</orderNumber>
<prodID>4</prodID>
<supplierName>test4</supplierName>
<productName>test4</productName>
<lastProd>Yes</lastProd>
</Order_MT>
</multimap:Message1>
</multimap:Messages>
CPI Message:
SantoshKabbur_0-1722256198587.pngSantoshKabbur_1-1722256574595.png

 

 

Regards,

Santosh



 

 

Dagmar
Explorer
0 Kudos

thank you SantoshKabbur - if you dont mention the "last message", instead you will write: "false()" and you will just define CompletionTimeout - e.g. 1 minute,  does that mean, that the message is sent after all items have been processed + 1 minute?

or does not matter that the messages have not been processed all, it will send to the next step after 1 minute?

 

Thank you,

BR
Dagmar

SantoshKabbur
Discoverer
0 Kudos

Hi Dagmar,

I simulate the same scenario by using Last message as "false()" after 1+mins also request is collecting in Data store and Whenever the iflow hits will  be closed then it iflow will wait for 1 more mins and providing the response. Thanks for your suggestions so i can implement the same scenarios in payments.

SantoshKabbur_0-1722259924143.png

 

Thanks,

Santosh

DipteeSawant
Newcomer
0 Kudos

@pkaushiksrinivas as per the SAP Note 3246831 SAP CPI idoc sender adapter cannot process bulk idoc from SAP ECC, then how did you achieve the same in the iFlow demonstrated in this blog?

Regards,

Diptee 

Labels in this area