Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Break From Iteration

Hello,
I'm downloading from FTP, and unfortunately, I cannot delete due to permission.
Therefore, I need to iterate fix number of times (instead of iterate through all the files).
Option 1 - Limit within Iteration count
I will download all files, but use tFileList to only import last 3 files (order by filename).
What's the best way to break from an iteration in tJava? I can set context variable, and if it iterates over the threashold, what command can I use to break the iteration?
Option 2 - Limit FTP Download (only last couple days instead of all files on FTP)
This would be the most efficient option, but could be more complicated, so if someone has a good solution, I would be interested to know about it.
Your help is appreciated!
Labels (4)
6 Replies
alevy
Specialist
Specialist

See my screenprint for an example of how to break an iteration.
You can also use tFTPFileList iterating to tFTPFileProperties-->tJavaRow then RunIf to tFTPGet to only download those files you want.
Anonymous
Not applicable
Author

Hi Adam,
Just asking out of my curiosity.
Instead of "break", what if we mention "continue", the loop should continue with the next record, right?
alevy
Specialist
Specialist

Yes, it would jump over any components/code after that statement and start the next iteration, exactly the same as if you were writing your own loop. View the code the studio generates to see exactly what's happening.
Anonymous
Not applicable
Author

Hi,
The screen shot appears to be missing.
Sorry for dragging this thread back form the dead but I'd be interested to know how to continue(skip the current) iteration.
I currently have the following;
tFlowToIterate->(LoadsOfCode)->RunIf->tJava
If possible I would like to be able to do something in the tJava that will skip/continue the current iteration and move onto the next.  I know this can be done using other methods but would specificity like to know about continuing from tFlowToIterate iterations.
Cheers Andy
Anonymous
Not applicable
Author

Ok in its basic form this is very easy, see screen belowe;
0683p000009ME0a.png
continue; to continue or break; to break...
However my job is alot more complex;
0683p000009ME0f.png
Any ideas how i can continue the "loop list" iteration based on the result from the subsequent API call (No records or error code)?
The warning i get in the tJava is "continue cannot be used outside of a loop".
schwarben
Contributor
Contributor

Hi,

 

Sorry for draging this thread back from the undead, but I hope this might help others as it might have helped me.

I am using Talend Studio 6.4 and it seems there has been some changes since the answer provided by moinerus. The iteration loop index is now associated with the tFlowToIterate component. One would therefore write something like :

 

if ( (Integer)globalMap.get("tFlowToIterate_1_CURRENT_ITERATION") > 3 == 0) {break;};

 

in the tJava component following the iterate link.

 

As for the initial question, one can achieve a fixed number of loops with the tLoop component.