You require the function useOneAsMany() if a field that only occurs once needs to be replicated as often as another field occurs in the outbound message so that the fields can be written to the target structure in pairs as a record.
In the following test instance in which purchase orders are sent, there are two examples for the use of useOneAsMany():
· The purchase orders (structure nodes order) are first divided by type (external or internal). The field type may only occur once in the structure order. Multiple itemGroup substructures can follow in which different items are listed by their name (field name), which all belong to one category. However, in the target structure, the purchase order type and the name of the item are to be saved in pairs (<external, Fender Strat V1>, <external, Ovation Light>, <external, Sticks (Standard)>).
· Equally, there can only be one category (field category) within an itemGroup but multiple named items (field name). The category is also written to the same record as the value of the fields name and type (<external, Guitars, Fender Strat V1>, <external, Guitars, Ovation Light>, <external, Percussion, Sticks (Standard)>).
The structure of the source and target messages are described by the following XSD defintions:
Source and Target Structure
Field Name |
Occurrence |
Field Name |
Occurrence |
OrdersByType |
1..1 |
OrdersByRecords |
1..1 |
order |
0..unbounded |
record |
0..unbounded |
type |
1..1 |
orderType |
1..1 |
itemGroup |
1..unbounded |
itemCategory |
1..1 |
category |
1..1 |
itemName |
1..1 |
name |
1..unbounded |
|
|
Before we look in more detail at how useOneAsMany() is used, let us look at the entire message mapping:
Message Mapping with useOneAsMany()
Target-Field Mapping (and Explanation) |
/OrdersByRecords/record= (a record is to be created in the target structure for each occurrence of name) |
/OrdersByRecords/record/orderType= (see below) |
/OrdersByRecords/record/itemCategory= (see below) |
/OrdersByRecords/record/itemName= (a context in the source structure can contain multiple name values) One value is to be transferred to each record context in the target structure. Therefore, by using SplitByValue(), you can insert additional context changes. |
Example Test Case
Source Instance |
Result |
<?xml version="1.0" encoding="UTF-8"?> <ns0:OrdersByType xmlns:ns0="http://com.sap/b"> <order> <order> <order> </ns0:OrdersByType> |
<?xml version="1.0" encoding="UTF-8"?> <ns0:OrdersByRecords xmlns:ns0="http://com.sap/b"> <record> <record> <record> <record> <record> <record> </ns0:OrdersByRecords> |
The use of useOneAsMany() is now to be explained by using the target-field mapping for the target field orderType:
The function useOneAsMany() has three input parameters:
To be able to take one value from the result queue of useOneAsMany() for each record, use the function SplitByValue(). It inserts a context change after each value of the result queue.
Using useOneAsMany() to create pairs from category and name functions in the same way.