Powered By

Free XML Skins for Blogger

Powered by Blogger

Saturday, August 9, 2008

MapExampleFlatStructureToNestedTables in SAP XI

Problem

In this example, different Person records are mapped to a nested structure. In the source structure, a single person can have multiple records that contain different telephone numbers. The target structure only has one record per person; the element Telephones contains all the telephone numbers for this one person.

The example assumes that the Person records in the source structure are sorted by the field Id: Consequently, Person records with the same Id come one after the other in the source message. If this were not the case, you would have to use the sort function to sort the records by their ID.

Solution

This graphic is explained in the accompanying text

In the description for the individual target-field mappings, [Root Context] stands for the context MapExampleFlatStructureMessage in the source structure.

· Target-Field Mapping for Person:

Id [Root Context] -> SplitByValue [Value Changed] -> CollapseContexts -> Person

One Person record must be created in the target structure for each record in the source structure in which the same ID occurs. Since the values of Id are sorted, only the following steps are required:

...

a. Collect all values in one context and insert a context change after each value change in this context (SplitByValue)

b. Reduce the number of values per context to the first value, and then combine all contexts together in one context (CollapseContexts).

This means that exactly one Person node is created for each ID, even if it occurs more than once.

· Target-Field Mapping for Id:

Id [Root Context] -> SplitByValue [Value Changed] -> CollapseContexts -> SplitByValue [Each Value] -> Id

Apart from the last point, this target-field mapping is identical to SplitByValue: since the number of contexts in the Id queue must be identical to the number of values in the parent Person queue, you must enter a context change after each value with SplitByValue. See also: Advanced User-Defined Functions.

· Target-Field Mapping for Name:

Name [Root Context] -> SplitByValue [Value Changed] -> CollapseContexts -> SplitByValue [Each Value] -> Name

This target-field mapping functions in the same way as the target-field mapping for Id.

· Target-Field Mapping for TelephoneNumber:

This graphic is explained in the accompanying text

In this target-field mapping, all telephone numbers and IDs are first collected in one context. Then, in the list of IDs, SplitByValue inserts a context change after each value change. Since the list is sorted (see above), for each context, the ID queue contains exactly the same number of values as a person has telephone numbers. The IDs then just need to be replaced by the corresponding telephone numbers to produce the correct result queue for TelephoneNumber. The standard function formatByExample can perform this conversion.

No comments:

Archives