====== Build a hierarchy using function SplitToArray() ====== To derive a hierarchy from a given structure there is ideally a **parent-child** relationship of the individual tuples. In such a case, the function [[en:transformation:mappings:funktionen:gruppierung:buildhierarchy|]] can be used to create the hierarchy. __If a direct **parent-child** relationship is only possible via the sequence of tuples and unique **parent** or **child** characteristics((Similar to the handling of record types in FlatFiles.)), the following approach can be chosen:__ ===== Solution approach ===== We use the following functions and components: - [[en:transformation:mappings:variablen:doubledollar|]] - [[en:transformation:mappings:funktionen:string:splittoarray|]] - Selektionsmodus: concatenate - XPATH Filter ==== Procedure in Mapping ==== First we store the tupples all in a [[en:transformation:mappings:variablen:doubledollar|]] with name $$Position to run through them in the next step. We then filter out the tuples by **parent** or **child** characteristic to form a string containing the hierarchy((In this case we distinguish by the first 3 digits of the item number.)). By cleverly applying the selection mode "concatenate" on the rule sets and controlling the separators((Here "**,**" as separator for mainPositions and "#" for SubPositions.)) a string can be formed according to the following pattern: MainPositionID1,MainPositionID2#SubPositionID1#SubPositionID2,MainPositionID3#SubPositionID1 This hierarchy string can finally be split with [[en:transformation:mappings:funktionen:string:splittoarray|]] and the separator "**,**" into the main positions, which trigger **Positions** in the target object and then for sub-items are again individually resolved after the separator "#" into the sub-items, which are triggered in the shown example below **Positions** as **CustomItems** in the MiddleWare((Or in the respective target object.)). {{:howtos:splittoarray_build_hierarchy.jpg?nolink|}} {{:images:sign_warning.png?nolink|}}**Note:** If the same item numbers are expected to come in different positions, then the original position number must be taken into account when creating the hierarchy! ==== Advantage ==== We avoid an intermediate mapping((This would be a classic solution with extra mapping.)) which could contain the parent-child relationship.