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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
sofiene92
Contributor
Contributor

Create files dynamically

Hello,
I use TOS 2.3.1 and I'm working on a Java project.
I have a table with 3 fields : NOMFICHIER (which is the filename), DATE and RAPPORT.
These 3 fields are string fields, and their respective length : 12 for NOMFICHIER, 20 for DATE and 70 for RAPPORT.
After that, I want to create a file for each NOMFICHIER, but I don't know what component I have to use, and how to use them...
My table :
NOMFICHIER|DATE|RAPPORT
123456789.12|2008-05-29 11:42:34|Établissement : 123
123456789.12|2008-05-29 11:42:34|Nombre de A : 625
123456789.12|2008-05-29 11:42:34|Nombre de B : 2718
123456789.12|2008-05-29 11:42:34|Nombre de C : 9868
123456789.12|2008-05-29 11:42:34|Nombre de D : 196
987654321.12|2008-05-29 11:42:34|Établissement : 456
987654321.12|2008-05-29 11:42:34|Nombre de A : 515
987654321.12|2008-05-29 11:42:34|Nombre de B : 2688
987654321.12|2008-05-29 11:42:34|Nombre de C : 6459
987654321.12|2008-05-29 11:42:34|Nombre de D : 0

Finally, I want to put these data dynamically in respective new file (file positionnal), with dynamic filename :
File : 123456789.12.txt
NOMFICHIER|DATE|RAPPORT
123456789.12|2008-05-29 11:42:34|Établissement : 123
123456789.12|2008-05-29 11:42:34|Nombre de A : 625
123456789.12|2008-05-29 11:42:34|Nombre de B : 2718
123456789.12|2008-05-29 11:42:34|Nombre de C : 9868
123456789.12|2008-05-29 11:42:34|Nombre de D : 196
File : 987654321.12.txt
NOMFICHIER|DATE|RAPPORT
987654321.12|2008-05-29 11:42:34|Établissement : 456
987654321.12|2008-05-29 11:42:34|Nombre de A : 515
987654321.12|2008-05-29 11:42:34|Nombre de B : 2688
987654321.12|2008-05-29 11:42:34|Nombre de C : 6459
987654321.12|2008-05-29 11:42:34|Nombre de D : 0
I have tried with tFor, tForeach, tJava Row, toFlowtoIterate, but It doesn't work, what I have to do?
Thanks for your answers!

Sofiene92
Labels (3)
10 Replies
sofiene92
Contributor
Contributor
Author

Hello,

Nobody can answer me?
I have to put some screenshot to explain my problem?
Thanks,

Sofiene92
Anonymous
Not applicable

To create multiple files you need an iterative link or a sub job. The file name can come from a context, a global variable or a reference to a row from which you start the iterative link. More tricky is to move the data into the sub job or breaking-up the data for the iterative link, this really depends on how you collect and process the data. Possibilities are lookup (from database or file), a temporary file or a concatenated string.
So I guess you need to post your job if you really like get feedback on this.
sofiene92
Contributor
Contributor
Author

Thank you for your answer Vaiko.
The problem is the fact that I am a new user and I am not sure what component I have to use and how I have to use them.
I have tried with tJavaRow, tForEach, I have used a global var and I put it in filename, but every time, when I execute my job, Talend creates only one file : null.txt
So what possibility do you advise?
I have put some screenshots to describe my problem.
Sorry for my english...
Thanks!

Sofiene92
0683p000009MCHz.png 0683p000009MCPx.png
Anonymous
Not applicable

Hello,
Sorry for my english too !
there is two step to created files dinammically, :
first step, you can create a master job to call a subjob, with the tRunJob, for each filename from NOMFICHIER column.
use this component to do this :
tInputFileDelimited -main-> tUniqueRow -main-> tFlowToiterate -iterate-> tRunJob ( with filename as parameter )

Last step, design your subjob ( call by tRunJob) , to write your data in the rigth file !
tInputFileDelimited -main-> tFilterRow -main-> tOutputFileDelimited ( with context variable as filename )

You should read the "Reference Guide" before to use this components : http://www.talend.com/resources/documentation.php
sofiene92
Contributor
Contributor
Author

Hi,
thanks for your answers but I have problems concerning components parameters (documentation doesn't help me...), especially with tFilterRow.
When I execute Master Job, I have only one file : "null.log" whereas I want one file for each filename.
I am not sure concerning context variable...
I have put some screenshots to describe Master job and subjob :

Thanks!

Sofiene92
0683p000009MCQ2.png 0683p000009MCNY.png 0683p000009MCHq.png 0683p000009MCQ7.png 0683p000009MCQD.png 0683p000009MBnc.png
sofiene92
Contributor
Contributor
Author

Re,

I have resolved my problem, I have juste replaced ((String)globalMap.get("NOMFICHIER")) by context.getProperty("NOMFICHIER"), and now it works perfectly!
Thank you Emenuet for your help! 0683p000009MACJ.png
I don't know if you are french or not, but : Mille Mercis!!! 0683p000009MACJ.png

Best regards,

Sofiene92
_AnonymousUser
Specialist III
Specialist III

I try to do exactly the same, but I can't reproduce what you have done.
First, I must congratulate for having understood how the tFowToIterate works. No documentation about it. The same for understanding the iterate link, I can only find examples and documentation with a tFileList, for which it works perfectly.
The question: how do you get the value NOMFICHIER in the file you iterate? How do you set context property you get by context.getProperty("NOMFICHIER") or globalMap.get("NOMFICHIER")?
In advance, thank you for helping.
sofiene92
Contributor
Contributor
Author

Hello dawi!
Sorry for my late answer, I am not often here, and it's generally me who need help. 😉
I am note sure if it can help you but I have put some screenshot of father job (LOG_ETABLISSEMENT) and son job (LOG_ETB_SEC).
Concerning the son job, you can delete component tFilterColums, it is not useful.
To answer to your second question, you have to create a contexts variable in the son job, as you can see on the screenshot.
Then, always in son job, in tFilterRow, you have to put a condition (NOMFICHIER = context.getProperty("NOMFICHIER")).
Then, you put context property in filename (tFileOutputPositionnal RAPPORT_LOG_ETB), like in the screenshot.
Finally, to answer to your first question, in the father job, you get the value NOMFICHIER in the file you iterate thanks to tRunJob, you select your son job, and in Context Param, you select NOMFICHIER - row1.NOMFICHIER (cf. screenshot).
I tried it in my project (it's a Java project), and it's works!
I hope it will help you... 😉

Best regards,

Sofiene92
0683p000009MCQH.png 0683p000009MCQM.png 0683p000009MCOl.png 0683p000009MBhF.png
Anonymous
Not applicable

Merci sofiene92,
0683p000009MACJ.png Ca fait des heures (pour pas dire des jours) que je galère pour faire ça 0683p000009MACn.png