Page 1 of 1

Generate a Sequential file with a header and footer??

Posted: Wed Jun 21, 2006 12:46 pm
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?

Posted: Wed Jun 21, 2006 12:52 pm
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.

Posted: Wed Jun 21, 2006 12:56 pm
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

Posted: Wed Jun 21, 2006 2:30 pm
by chulett
I stick with one job to create all three files, then cat.

Posted: Thu Jun 22, 2006 6:56 am
by DSguru2B
Jules agrees with Craig. :wink:

Posted: Thu Jun 22, 2006 7:04 am
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...

Posted: Thu Jun 22, 2006 7:06 am
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.

Posted: Thu Jun 22, 2006 7:07 am
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.

Posted: Thu Jun 22, 2006 7:33 am
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

Posted: Thu Jun 22, 2006 7:43 am
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


Posted: Thu Jun 22, 2006 7:46 am
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.

Posted: Thu Jun 22, 2006 9:53 am
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

Posted: Thu Jun 22, 2006 1:53 pm
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.

Posted: Thu Jun 22, 2006 2:03 pm
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.

Posted: Thu Jun 22, 2006 4:33 pm
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: