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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Split input file into multiple outputs

Hi
I am a newbie and have been unable to find the answer to my problem on the forum. Any help would be appreciated.
The scenario I need to resolve is as follows:
Input file is a csv file which contains a batch header record followed by 'n' number of rows. The last record in the file is a simple batch trailer record. I need to split this single file into individual output files based on the content of the data in the rows including a dynamic file name, and recreate the new batch header and trailer records for each of the new files. The number of files created would vary based on the content of the original input file.
eg
input.txt
BH,all animals
mammal,cow
reptile,cobra
mammal,horse
bird,sparrow
reptile,crocodile
BT,5
Output for the above example assuming the split is on the first field would be:
mammal.txt
BH,mammal
cow
horse
BT2
reptile.txt
BH,reptile
cobra
crocodile
BT,2
bird.txt
BH,bird
sparrow
BT,1

Any assistance in how to structure the JAVA job would be much appreciated.
Regards
Andre
Labels (3)
10 Replies
Anonymous
Not applicable
Author

Hi Ashok,
do you have always one detail with a predefined mapping?
In this case you have two solutions (otherwise only the second one).
Solution one with "information transfer between two flows":
a)Read your file with tFileInputRegex ("^(.),(.*)$"). You now have two values: The row type and the data.
b) Split the stream in a tMap depending on the row type. The "C"-row must by the first in order.
c) In each output stream decompose data with tExtractDelimitedFields
d) In the flow of row "C" add a tJavaRow and set predefined context variables for your data you need in flow "M". (context.accountNumber= input_row.accountNumber for example)
e) In the flow of row "M" add a tJavaRow and add the values you need to the output (output_row.accountNumber= context.accountNumber). You must define the variables in the output schema (which will have mor than input). In this case you could ignore the warning appearing on tJavaRow.

Bye
Volker