# 再帰ループをマッピング

RecursiveLoopファンクションを使えば、入力再帰ループを類似する出力ループにマッピングできます。

## 始める前に

入力ストラクチャーと出力ストラクチャーを持つマップを作成済みであること。たとえば、CustomComponentを入力として、Componentを出力として使用できます。これらのストラクチャーは、[Other Projects] (他のプロジェクト) &gt; [Examples] (例) &gt; [Structures] (ストラクチャー) &gt; [Recursive] (再帰) &gt; [Component] (コンポーネント)の下にあります。

## このタスクについて

この例では、SubComponentsループが含まれているComponentエレメントが入力ストラクチャーに存在します。これは親と同じエレメントを使う再帰ループです。

![](https://help.qlik.com/talend/ja-JP/data-mapper-user-guide/Resources/images/recursive_loop_01_structure.png)

この再帰ループは、出力ストラクチャーの類似する再帰ループにマッピングされる必要があります。

このマップは、[Other Projects] (他のプロジェクト) &gt; [Examples] (例) &gt; [Maps] (マップ) &gt; [Looping] (ルーピング) &gt; [LoopSkipLevel]にあります。

## 手順

1. 入力Componentエレメントを対応する出力エレメントにドラッグします。
2. 入力ストラクチャーで、SubComponentsループを右クリックして[Expand Recursive Elements] (再帰的エレメントの展開)をクリックし、もう一度右クリックして[Expand All] (すべて展開)をクリックして子を表示させます。
3. 出力ループで前のステップを繰り返します。
4. 出力SubComponentsエレメントの[Loop] (ループ)タブで、RecursiveLoopファンクションをドラッグ＆ドロップします。
5. 入力SubComponentsエレメントをInput Map Element引数にドラッグ＆ドロップします。
6. 入力SubComponentsエレメントを対応する出力にドラッグ＆ドロップし、子をマッピングさせます。

   ![](https://help.qlik.com/talend/ja-JP/data-mapper-user-guide/Resources/images/recursive_loop_02_recursiveloop.png)

## タスクの結果

RecursiveLoopファンクションでは、再帰ループの最初のレベルにマッピングするだけで結構です。入力ファイルに存在する後続の全レベルに同じマッピングが適用されます。サンプル入力ファイルに基づいて出力を確認する場合は、[Test Run] (テスト実行)ボタンを使います。この例での出力は次のようになります。

```
<Component>
  <Id>1</Id>
  <PartNumber>45I1122</PartNumber>
  <Quantity>1</Quantity>
  <Description>Main Component</Description>
  <SubComponents>
    <Id>102</Id>
    <PartNumber>12ZSSS</PartNumber>
    <Quantity>5</Quantity>
    <Description>Door Assembly</Description>
    <SubComponents>
      <Id>201</Id>
      <PartNumber>88-B</PartNumber>
      <Quantity>2</Quantity>
      <Description>Hinge</Description>
    </SubComponents>
    <SubComponents>
      <Id>202</Id>
      <PartNumber>GF4488-B</PartNumber>
      <Quantity>1</Quantity>
      <Description>Lock</Description>
    </SubComponents>
    <SubComponents>
      <Id>203</Id>
      <PartNumber>288333-I10023</PartNumber>
      <Quantity>1</Quantity>
      <Description>Sign</Description>
    </SubComponents>
  </SubComponents>
  <SubComponents>
    <Id>302</Id>
    <PartNumber>12IQWO</PartNumber>
    <Quantity>14</Quantity>
    <Description>Window Assembly</Description>
    <SubComponents>
      <Id>401</Id>
      <PartNumber>88-C</PartNumber>
      <Quantity>2</Quantity>
      <Description>Window Lock</Description>
    </SubComponents>
    <SubComponents>
      <Id>402</Id>
      <PartNumber>RT433</PartNumber>
      <Quantity>1</Quantity>
      <Description>Window Frame</Description>
    </SubComponents>
    <SubComponents>
      <Id>403</Id>
      <PartNumber>15</PartNumber>
      <Quantity>1</Quantity>
      <Description>Glass</Description>
    </SubComponents>
  </SubComponents>
</Component>
```