Creating a File Header

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

Creating a File Header

Post by JezT »

I have created two after job routines. One adds a trailer to the output file from a job and the other is meant to add a header.

The problem is that although the Write Trailer works fine, the Write Header routine is adding the line at the bottom of the file and not the top.

Any suggestions ?

Is there a way of using a before job routine to create the header before the output is added to the file ?
prabu
Participant
Posts: 146
Joined: Fri Oct 22, 2004 9:12 am

Re: Creating a File Header

Post by prabu »

JezT wrote:I have created two after job routines. One adds a trailer to the output file from a job and the other is meant to add a header.

The problem is that although the Write Trailer works fine, the Write Header routine is adding the line at the bottom of the file and not the top.

Is there a way of using a before job routine to create the header before the output is added to the file ?
try something like in the Before routine

Code: Select all

echo  headermessage >> yourfile.txt
BTW, whats your <b>current</b> Write Header routine[/code]
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Depends on what your header information contains. If it is supposed to contain information about the row count, you have to create the header row after you created the file.

Why not let DataStage create your file, then use an after-job script call to create the header and trailer record and then assembled the completed file? Your on unix, do something like:

1. create a header record header.txt
2. create a trailer record trailer.txt
3. issue a cat statement like:

Code: Select all

cat header.txt datafile.txt trailer.txt > finalfile.txt
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What I generally do is create all three in the same job... or seperate jobs, if that is not possible. An after job then creates the final product by 'catting' the three files together:

Code: Select all

cat header detail trailer > final_file
You could do something similar. Either that or create your header record first and change your job that creates the detail to append to it... but it might complain about the metadata mismatch. :?

I prefer building the three pieces and then sticking them together into a new file.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Dang, Ken, will you stop following me around and typing faster than me! Sheesh...
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply