Multi-mapping is a method of message transformation wherein one or more source messages can be combined or split to generate one or more target messages. We can have three types of multi-mapping transformations – 1:n, n:1, and n:m mapping transformation. In this article, we will understand how to create and use 1:n multi-mapping transformation in a BPM scenario.
Lets say, we have a source message as shown on the left. It contains combined data of a set of sales orders. The node OrderData can occur n number of times where n≥1. And we have the target structure as shown below wherein the node OrderData can occur exactly once. Thus our aim is to read one message from source system and generate n messages at the target system, where n = number of orders (OrderData nodes) present in the source message.
Create the required data types (Structures here), message types, and message interfaces. We will need four asynchronous message interfaces: one for outbound message, one for inbound message and two abstract interfaces one each for the source and the target message.
Now create a mapping program (say MM_Orders). Select the source and target message types. Go to the Messages tab and change the occurrence of the target message to 0..unbounded (see figure on the left). Come back to the Design tab and define your transformation logic. Here is the complete graphical mapping.
Since the nodes CompanyCode and SalesArea occur only once in the source structure and should be generated in every target structure, we need to use node function useOneAsMany as shown in the figure below to map these fields from source to target. For more details about useOneAsMany function refer this article.
Once you have completed the message mapping go to the Test tab, right-click the node OrderData and use Repeat Subtree option 2-3 times. Then execute the mapping program to verify that multiple messages structures are indeed generated at the target side.
Create an Interface Mapping (say IM_Orders) using the abstract interfaces defined for source and target messages. We need to use abstract interfaces as we will be using this mapping within the BPM process definition. Make sure you change the occurrence of the target interface to 0..unbounded.
Now, create an Integration Process (BPM) as shown below.
Define two container elements Source and Target for the two abstract interfaces as shown below. Note that the element Target must be a Multiline element since we need to generate multiple messages at the target. We will define CurrentLine element later during the block step.
Receive Step: Asynchronously receives the source message.
Transformation Step: Transforms the Source to Target using the transformation defined by the Interface Mapping.
Block Step: Select ForEach mode. In ForEach mode the block executes for each line of multiline container element and completes either when the End Condition returns true or when all the lines of multiline container element get processed. The end condition is checked as soon as the block processes the first line of multiline container element.
A single line container element needs to be defined to hold the Current line of the multiline element. Select the Block and define a new container element (say CurrentLine) as shown previously. Note that this element is visible only within the specified block. No need to define end condition as we want to process all the elements of the multiline container element.
Send Step: Define a send step within the ForEach block. This step sends out the contents of CurrentLine element asynchronously one by one.
Check your BPM using F7 key. Activate the change list. Then complete the directory configuration. You will require one sender agreement; one receiver/interface determination each for source system to BPM and BPM to target system and one receiver agreement.
You can use file systems as the source and the target systems in which case you can define file adapters at the sender and receiver side.
Once all the changes have been activated, test your interface by putting a file containing data for multiple orders in the source directory. Open and check the target directory to see whether the specified number of files have been correctly generated.