How to create 2 headers , detail , trailor

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
sreev22
Participant
Posts: 1
Joined: Mon Oct 29, 2007 8:43 pm
Location: boston

How to create 2 headers , detail , trailor

Post 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.
stefanfrost1
Premium Member
Premium Member
Posts: 99
Joined: Mon Sep 03, 2007 7:49 am
Location: Stockholm, Sweden

Post 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))
-------------------------------------
http://it.toolbox.com/blogs/bi-aj
my blog on delivering business intelligence using agile principles
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply