Page 1 of 1

How to create 2 headers , detail , trailor

Posted: Tue Oct 30, 2007 8:37 am
by sreev22
How to create two Headers , detail , footer for fixed length file.

My requirement is like in row1 there should a file header , row2 ---Header section,row 3 detail , last row ---footer of the output file. Please advice.

Posted: Tue Oct 30, 2007 9:40 am
by stefanfrost1
one way to do this is to add an transformer before your seqential file stage and convert all columns to one column with fixed length and pad each field and then concatenate them togheter and within that stage add two new records first in your output and than a trailer record at the end. When you've created your one column schema its easy to add new rows regardless of what schema that row has, such as headers and trailers. For example you got use a row generator for those headers and trailer and funnel them togheter and sorting in some way.

Even better add three outputs from the transformer where one only has the headers and one the details (as below) and the third the trailer. Later in a funnel stage you can get them in the correct order if i am not mistaken (otherwise add a sort column and sort in sequntial mode before writing).

An advantage of having it all in a transformer is if you for example want the trailer to have a no of records count or a checksum of some kind (based on the details). Header can also be produced based on the details perhaps. An example could be to populate a header with number of hours that each store has sent us their retail information and from how many cashiers (this is part of a header and based on input details). The trailer consists of a total amount of sales per file (which is store and day).

Example

schema out:
outcol1 200 char

schema in:
incol1 int
incol2 char 10
incol3 varchar 180

transformation

PadString(DecimalToString(incol1)," ",10-Len(DecimalToString(incol1))) : incol2 : PadString(incol3," ",180-Len(incol3))

Posted: Tue Oct 30, 2007 8:43 pm
by ray.wurlod
Another way, particularly if the headers and trailers have static text, is before/after subroutines. In the before-job subroutine you echo the two header lines into the file.

Code: Select all

echo Header1 > #filename#
echo Header2 >> #filename#
In the job itself you append to #filename#
In the after-job subroutine you echo the trailer into the file.

Code: Select all

echo Trailer >> #filename#
Adapt to suit your particular requirements. You can go overboard and use OpenSeq, Seek, WriteSeq and CloseSeq statements in your routines if you wish.