Similar to the previous use case, you may want to generate several files whose names will depend on the content they will have. Suppose you want to generate several sales files, one per product line. The filenames would be sales_<product line>.txt as in sales_Cars.txt. You will know the names only when you have the data ready to be sent to the output file. Doing this is really simple, as shown next:
- Open the Transformation that reads the sales_data.csv file, and save it with a different name.
- After the Text file input step, add the UDJE step. We will use this step for defining the name of the output files.
- Double-click the UDJE step and add a new field named filename, of type String. As Java expression, type "D:/LearningPDI/files/sales_" + PRODUCTLINE + ".txt". Change the path if you want to generate the file in a different folder.
- Close the window. Make sure the UDJE step is selected; then run a preview. You should see this:
Previewing filenames
- After UDJE, add a Text file output step.
- Just as you did before, double-click the Text file output step. Check the Accept file name from field? option. As File name field, select the field created in the previous step, filename.
- In the Content tab, leave the default values.
- Select the Fields tab and configure it as shown next:
Configuring the fields grid in an output step
- Click on OK, save the Transformation, and run it.
- Browse your file system. You should see one file per product line in your sales_data.txt file.
- Open the sales_Planes.txt file. You should see this:
PRODUCTLINE;PRODUCTCODE;QUANTITYORDERED;PRICEEACH;SALES
Planes ;S24_4278 ;23;$74,62;$1716.26
Planes ;S700_4002;26;$85,13;$2213.38
Planes ;S700_2834;48;$68,80;$3302.40
Planes ;S24_2841 ;43;$82,21;$3535.03
Planes ;S24_3949 ;21;$55,96;$1175.16
Planes ;S700_4002;44;$85,87;$3778.28
Planes ;S72_1253 ;45;$51,15;$2301.75
Planes ;S700_4002;35;$100,00;$4277.35
Planes ;S700_1691;39;$100,00;$5043.87
Planes ;S24_4278 ;35;$83,32;$2916.20
...