CPI-Aggregator Use Case-Create separate messages per unique Company Code
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.
- 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 :
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.
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)
- Instead of writing complex mappings to achieve the above requirement, Aggregator makes it easier to group the message based on Correlation condition
- 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.
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.