Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I want to add a header dynamically in my CSV file
below is my CSV File which i get after my mapping.In that first row will be added dynamically . FUEL should be taken from sheetname and system date and then the count of the row in output file
How can i achieve it?
OK, this is how I would do it.
You will need the tHashInput and tHashOutput components for this. If you do not have those available, you will need to find them. Take a look here for that...
Your job will look like below.
The top subjob will be pretty much like yours is now, but you will replace the tFileOutputDelimited with a tHashOutput.
The next subjob uses a tFixedFlowInput with 2 columns. One for row count and one for file name. You can get the row count using a globalMap variable like this....
((Integer)globalMap.get("tFileInputExcel_1_NB_LINE"))
....check the name of your tFileInputExcel. Mine is called tFileInputExcel_1. Change the above variable key with the name of your component.
The filename you can get from however you specify the file for the component. If it is a variable, use that. If it is hardcoded, it will always be the same. I can't answer this bit for you without having your job.
This data needs to be written to your tFileOutputDelimited. It will be the first row.
The last subjob is where your data is added to the file. Simply link the tHashInput to the tHashOutput where you saved the data in memory above (the first subjob). Make sure the schema is that same as the tHashOutput. Then connect it to another copy of the tFileOutputDelimited. Make sure the schema of the tFileOutputDelimited is the same as the tHashInput. The ONLY change in the tFileOutputDelimited is that you must tick the "Append" tickbox.
If this is done correctly the first subjob will read the data into memory. The second subjob will write the row count and filename to the file. The third subjob will write the data stored in memory to the file after the row count and filename.
This needs a bit more of an explanation. You say you want a dynamic header, does that mean that the header will hold dynamic data or that you simply want it added after you have read the file? My assumption is that you simply want to take the filename and row count and add it to the top of the file. Is that correct? By the way, the sheet name of a CSV file viewed in Excel is the filename. If you post a screenshot of your job which gets you to this point (the file you've shown), I can point you in the right direction to achieve this if my assumption above is correct.
Hi,
Yes you are correct i need to add the file name and count of row to be added at the top of my file. as of now my flow is like
tFileInputExcel->tMap->tFileOutputDelimted. please guide me
OK, this is how I would do it.
You will need the tHashInput and tHashOutput components for this. If you do not have those available, you will need to find them. Take a look here for that...
Your job will look like below.
The top subjob will be pretty much like yours is now, but you will replace the tFileOutputDelimited with a tHashOutput.
The next subjob uses a tFixedFlowInput with 2 columns. One for row count and one for file name. You can get the row count using a globalMap variable like this....
((Integer)globalMap.get("tFileInputExcel_1_NB_LINE"))
....check the name of your tFileInputExcel. Mine is called tFileInputExcel_1. Change the above variable key with the name of your component.
The filename you can get from however you specify the file for the component. If it is a variable, use that. If it is hardcoded, it will always be the same. I can't answer this bit for you without having your job.
This data needs to be written to your tFileOutputDelimited. It will be the first row.
The last subjob is where your data is added to the file. Simply link the tHashInput to the tHashOutput where you saved the data in memory above (the first subjob). Make sure the schema is that same as the tHashOutput. Then connect it to another copy of the tFileOutputDelimited. Make sure the schema of the tFileOutputDelimited is the same as the tHashInput. The ONLY change in the tFileOutputDelimited is that you must tick the "Append" tickbox.
If this is done correctly the first subjob will read the data into memory. The second subjob will write the row count and filename to the file. The third subjob will write the data stored in memory to the file after the row count and filename.
Thanks alot it works now.
What did happen here? I dont see the answer in the blog.