Mapping nested loops - 8.0

Talend Data Mapper User Guide

Version
8.0
Language
English
Product
Talend Big Data Platform
Talend Data Fabric
Talend Data Management Platform
Talend Data Services Platform
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Design and Development > Designing Jobs
Last publication date
2024-03-28
Map input nested loops to different output nested loops. Nested loops indicate that you want to iterate at the deepest level of a loop hierarchy while preserving the possibility to access the data from the parent loops.

Before you begin

You have created a map with an input and output structure. For this example, you can use POFile as input and SimpleShipNoticeFile as output. These structures can be found under Other Projects > Examples > Structures > Simple > POStandard.

About this task

In this example, three levels of input looping elements need to be mapped to two levels in the output. The output Notice element needs to loop on the input Delivery loop, but it also needs to use the Number element from the parent PO loop.

This map is available in Other Projects > Examples > Maps > Looping > LoopSkipLevel.

Procedure

  1. Drag the input PO/Number element to the output Num.
    A looping expression with a SimpleLoop function is added to Notice.
  2. Drag the input DeliveryToName to the output Name.
  3. In the dialog box that opens, select Change the output element looping and click OK.
    A NestedContext function is automatically added to the Context argument of the SimpleLoop in the Notice element. Another SimpleLoop is added to the NestedContext, and it uses a reference to the input Delivery loop as an argument.
  4. Optional: Map other elements as needed.

Results

The use of the NestedContext indicates that there should be one Notice element for each input Delivery loop contained in each PO loop. The sample input document contains two PO elements, one containing a single Delivery and the other containing two occurrences. If you use the Test Run, you should have three Notice elements:
<Notices>
  <Notice>
    <Num>1</Num>
    <Name>Francis Upton</Name>
  </Notice>
  <Notice>
    <Num>2</Num>
    <Name>Francis Upton</Name>
  </Notice>
  <Notice>
    <Num>2</Num>
    <Name>Martha Lyman</Name>
  </Notice>
</Notices>