Skip to main content Skip to complementary content

Unrolling a loop

Unroll a loop to create a separate element that does not loop.

Before you begin

You have created a map with an input and output structure. For this example, you can use Other Projects > Examples > Structures > Recursive > Component as input and Other Projects > Examples > Structures > CSV > FlatComponents as output.

About this task

In this example, the input structure has a Component element containing a recursive SubComponents loop. In the output, the SubComponents loop should be a simple loop on the same level as Components.

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

Procedure

  1. In the input structure, right-click the SubComponents loop and click Expand Recursive Elements, then right-click it again and click Expand All to show its children.
    You can repeat the same steps on the child SubComponents elements to display as many levels as needed.
  2. In the output structure, right-click the Components loop and click Unroll From Loop.
    This creates a new non-looping Components element with all its children.
  3. Drag the input Component element to the output Components (Unrolled from Loop).
    The elements with the same name in both structure are automatically mapped.
  4. Drag the input SubComponents to the output Components[2] loop.
    The elements are mapped and a SimpleLoop function is added to the output looping element.
  5. Click the output Row element, then drag a FixedLoop function from the Functions tab and drop it in its Loop tab.
    The Row element is a loop and therefore needs a looping expression. However, since the input Component does not loop, you do not need several occurrences of Row in the output. The FixedLoop function indicates the number of occurrences to return (by default it is set to 1).

Results

The loops are mapped, you can use the Test Run button to see the output based on the sample input file. In this example, the output looks like this:
<FlatComponents>
  <Row>
    <Components>
      <Id>1</Id>
      <PartNumber>45I1122</PartNumber>
      <Quantity>1</Quantity>
      <Description>Main Component</Description>
    </Components>
    <Components>
      <Id>102</Id>
      <PartNumber>12ZSSS</PartNumber>
      <Quantity>5</Quantity>
      <Description>Door Assembly</Description>
    </Components>
    <Components>
      <Id>302</Id>
      <PartNumber>12IQWO</PartNumber>
      <Quantity>14</Quantity>
      <Description>Window Assembly</Description>
    </Components>
  </Row>
</FlatComponents>

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!