Adding a header and trailer to a file
This recipe details a method for creating a file with a header and trailer record, which makes use of file append.
Getting ready
Open the jo_cook_ch08_0090_createHeaderAndTrailer
job.
How to do it...
The steps for adding a header and trailer to a file are as follows:
Open the
tFixedFlowInput_1
component.Add the following for the field
fileDate
;TalendDate.getDate("CCYY-MM-DD")
.Open the
tFixedFlowInput_2
component.Add the following for the field
fileDate
;((Integer)globalMap.get("tFileInputDelimited_1_NB_LINE"))
.Open
tFileOutputDelimited_1,
and change the type toAppend
.Open
tFileOutputDelimited_4,
and change the type toAppend
.Run the job, and if you examine the output file, you should see that it has created a file with the current date in the header and the correct number of detail lines in the trailer.
How it works...
tFixedFlowInputs
are used to generate a single row each for the header and the trailer.
The header sub job will create the file and add the...