Talend tLoop

Talend tLoop is the same as For Loop or While loop. Use this Talend tLoop component to execute another component or job for a given number of times. This section covers multiple examples of the Talend tLoop to help you understand it completely.

Talend tLoop Example

Drag and drop the Talend tLoop component to the job designer window.

Talend tLoop 1

As you can see from the tLoop below, it has For loop and While loop options. Please choose as per your requirements, and for now, we kept it as For loop. Next, it has From, To, and Steps options with default values. It is same as for(i = 1; i <= 10; i++) or for(i = 1; i <= 10; i+1)

Talend tLoop 2

To display the iteration values, we used the tJava component. Within the Talend tJava, we add the Java println statements to print the current loop value in the iteration.

System.out.print(((Integer)globalMap.get("tLoop_1_CURRENT_VALUE")));
System.out.print("\t Ieration No = " + ((Integer)globalMap.get("tLoop_1_CURRENT_VALUE")));
System.out.println();
Talend tLoop 4

Let me run this Talend tLoop job and see the output. As you can see, iteration started at one and ended at 10 with an increment of 1.

Talend tLoop 5

This time, we used the tRowGenerator to generate random rows for each iteration. For this, first, we changed the For loop maximum or value to 5.

Talend tLoop 6

Within the tRowGenerator editor, we added four different columns. Next, we changed the number of rows to 2 which will generate two random rows.

Talend tLoop 7

Next, we added the tLogRow to display the result. In general, the tRowGenerator has to generate two rows and four columns. However, we used the tLoop to iterate the tRowGenerator. It means for each loop iteration, tRowGenerator has to generate two random rows. So, the total records will be five iterations * 2 random rows = 10.

Talend tLoop 8

You can see the tLoop output.

Talend while Loop 9

To make this interesting, we added one more row whose value is the tLoop current value. Use Control + Space to get the suggestions.

Talend while Loop 10

Next, we changed the to value to 3 to accommodate all the results in the single screenshot.

Talend for Loop 11

Now, you can see two randomly generated rows for each iteration.

Talend for Loop 12