# Setting a number of loop iterations in a flat structure

Use a SetElementProperty to define the number of loops to read for an element and ignore other iterations.

## Before you begin

You have a flat file to use as sample document. You can create one from the sample data provided below.

## About this task

In this example, you have a flat file containing three elements named a, b and c. The b element is a loop and you want to set a number of loop iterations that should be read and ignore the others. This can be done by setting the Occurs Min/Max values in the element properties, however, using a SetElementProperty instead can be useful if you want to change that value in a map without impacting the structure.

You can use the following data for your sample input:

```
a1b1b2b3b4b5c1
```

## Procedure

1. Create your structure:
   1. In the Hierarchical Mapper, right-click Structures and click New &gt; Structure.
   2. In the wizard that opens, select Create a new structure where you manually enter elements and click Next.
   3. Select a folder and enter a name for your structure, then click Next.
   4. Select the Flat Files representation and click Next.
   5. Click Import a file as document and click Next.
   6. Browse to the relevant folder and select your flat file, then click Finish.
2. Right-click the section on the left of your workspace and click New Element to create a root element.
3. Right-click the root element and create three child elements named a, b and c.

   Your structure looks like this: ![Creation of elements.](https://help.qlik.com/talend/en-US/data-mapper-functions-reference-guide/Resources/images/set_number_of_loops_01_structure.png)
4. Click the a element and enter 2 in both Size Min/Max fields, then enter the same values for the c element.
5. Click the b element and enter 1 in the Occurs Min field, 100 in Occurs Max and 2 in both Size Min/Max fields.

   This indicates that the element must occur once and can occur up to 100 times, and each iteration has a size of two bytes. ![Properties for b element.](https://help.qlik.com/talend/en-US/data-mapper-functions-reference-guide/Resources/images/set_number_of_loops_02_b_element.png)
6. Place a SetElementProperty function in the Util tab of the b element.
7. Double-click the SetElementProperty function and select Loop Count in the Property drop-down list.
8. Place a Constant function on the Value argument, then double-click the function, enter 3 in the Value field and click OK.

   This indicates that only the first three iterations of the b elements should be read. ![Placement of Constant function.](https://help.qlik.com/talend/en-US/data-mapper-functions-reference-guide/Resources/images/set_number_of_loops_03_setelementproperty.png)

   The number of loops to read is defined but an error appears because there are no instructions on how to process the rest of the file.
9. Place a SetElementProperty function in the Util tab of the c element and leave the default Byte offset property.
10. Place a Constant function on the Value argument, then double-click the function, enter 12 in the Value field and click OK.

    This expression indicates that the c element starts 12 bytes after the first byte in the document, which means that the two loop iterations ignored in the b elements are discarded and not read as part of the c element.

## Results

Your structure is configured. If you want to check that the properties are correct, you can create a map with this structure as both input and output. ![Structure result.](https://help.qlik.com/talend/en-US/data-mapper-functions-reference-guide/Resources/images/set_number_of_loops_04_map.png)

When using the Test Run feature, you should get the following result:

```
a1b1b2b3c1
```

If needed, you can change the Loop Count property in the map, without impacting the structure or any other map which uses it.