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.
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)
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();
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.
This time, we used the tRowGenerator to generate random rows for each iteration. For this, first, we changed the For loop maximum or to value to 5.
Within the tRowGenerator editor, we added four different columns. Next, we changed the number of rows to 2 that will generate two random rows.
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.
You can see the tLoop output.
To make this interesting, we added one more row whose value is the tLoop current value. Use Control + Space to get the suggestions.
Next, we changed the to value to 3 to accommodate all the results in the single screenshot.
Now, you can see two randomly generated rows for each iteration.