Generate a Sequential file with a header and footer??

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
DeepakCorning
Premium Member
Premium Member
Posts: 503
Joined: Wed Jun 29, 2005 8:14 am

Generate a Sequential file with a header and footer??

Post by DeepakCorning »

We have a requirement to write to a sequential file from a table. its not complex and is one to one mapping. But the thing is that we want to include a header and a footer to the file. Is it possible to do it in Datasatge??

I was wondering a work out such as union with a dummy table to generate this header row, but will like to know if there is a direct function present in datasatge or not?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Typically, you'll want to generate the three files separately - header, detail, footer - and then cat them together in the proper order after job.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Shree0410
Participant
Posts: 70
Joined: Tue Nov 29, 2005 7:25 pm

Post by Shree0410 »

3 jobs, the one that creats header, should be a 'overwrite' of the file, means new and the one that extracts data from table will be second in the sequence which appends and then the third one that writes the trailer will be the last in the sequence that should also append
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I stick with one job to create all three files, then cat.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Jules agrees with Craig. :wink:
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
parag.s.27
Participant
Posts: 221
Joined: Fri Feb 17, 2006 3:38 am
Location: India
Contact:

Post by parag.s.27 »

Yes you can do it in a single job......
just create 3 files with header, details and footer....

and then use Link collector having proper link execution order...
Thanks & Regards
Parag Saundattikar
Certified for Infosphere DataStage v8.0
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

parag.s.27 wrote:Yes you can do it in a single job......
just create 3 files with header, details and footer....

and then use Link collector having proper link execution order...
I dont think that would work, unless the "details" has a single record.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Or before job subroutine to create a file with header. And append the file in the job with detail. And later cat with the trailer in after job subroutine.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
parag.s.27
Participant
Posts: 221
Joined: Fri Feb 17, 2006 3:38 am
Location: India
Contact:

Post by parag.s.27 »

no it will coz i did that just include 2 stage variables stgcnt1 and stgcnt2

then increment as stgcnt1+1 for stgcnt1
and
stgcnt2+1 for stgcnt2

and apply constraint..
for header- if stgcnt1=1 then.......
then simply details
and then footer as
if stgcnt2=1....

coz this will be satisfied only once
Thanks & Regards
Parag Saundattikar
Certified for Infosphere DataStage v8.0
parag.s.27
Participant
Posts: 221
Joined: Fri Feb 17, 2006 3:38 am
Location: India
Contact:

Post by parag.s.27 »

to be more precise


Code: Select all


    Header Data sequential file
               |if Stgcnt1=1 then (write the header data)1\
               |                                                              
------>transformer--------->details2----------------2---Link collector
               |                                                         
               |if Stgcnt2=1 then (write footer data)3--/
    footer Data sequential file

Thanks & Regards
Parag Saundattikar
Certified for Infosphere DataStage v8.0
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Thats fine. But the link collector will go for roundrobin processing. It will take the first record from 1, first record from 2 and then first record from 3, then come back to 2 and continue.
SO your output file will look like
header
detail
trailer
detail
detail
.......
.......
.......
.......
Thats what i mean. Its not the logic inside the transformer, its the way link collector will work.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
parag.s.27
Participant
Posts: 221
Joined: Fri Feb 17, 2006 3:38 am
Location: India
Contact:

Post by parag.s.27 »

My mistake as usual...

hope this will help : -

first create file with header and detail data....and then use another link collector to include trailer to that newly created file.....

yup its complex....

so
Header + Detail = 1st link collector..
then
Header + Detail + Footer = 2nd link collector
Thanks & Regards
Parag Saundattikar
Certified for Infosphere DataStage v8.0
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You could also use ExecSH (or your own routine) as a before-job subroutine to echo the header into the file, append detail records in the job and use ExecSH (or your own routine) as an after-job subroutine to append the trailer using echo and the >> redirection operator.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DeepakCorning
Premium Member
Premium Member
Posts: 503
Joined: Wed Jun 29, 2005 8:14 am

Post by DeepakCorning »

Thanks guys for replying back for this doubt. And after going through all these rplies it seems its not that easy task which i was thinkng of. Well I will try any of the solutionf and see which one works.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Actually, I think it's a very easy task to accomplish. You can complicate it if you like, but it really can be distilled down to one job that creates three separate files and concatendates them together when it is done. Easy Peasy. :wink:
-craig

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