Deletion of output file

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

Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Deletion of output file

Post by Latha1919 »

Hi,

I have a Job writing data to four .csv files (in the Sequential file stages) at the end. I do have constraints defined for these satges.

Even though there's no data written to the file, that particualr file is still created in the folder. How do I overcome this issue? I would like the file to be erased, when there's no data written to it.

Please advise.

Thanks
dsx
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Yup, that's the way it works. When the stage is 'started' the file is opened and created as a zero byte file if needed. There's no 'only create it if I write to it' option.

You'll need to do something after job, a script or batch file or routine that checks for a zero size and deletes if it is.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

File will be definetly create when you have the link.
Either you need to pre process or Post process for this.
Either you can check for the size and remove it from the OS or pass different value to the parameter to the job if the file need not to be create at some specific condition, say /dev/null.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

There's no option of After-stage routine for seuential file stage.
dsx
DeepakCorning
Premium Member
Premium Member
Posts: 503
Joined: Wed Jun 29, 2005 8:14 am

Post by DeepakCorning »

What about the after job subroutine??
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You are correct. There is no option. You will have to write you own routine to detect a file with size zero and issue a delete command at the os level.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You could do it 'after stage' from the transformer that feeds the Sequential stage, but I did specifically say '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 »

The simplest way is to create a script file on the OS to have the logic to delete file if the file size is 0 or record count is 0 and execute this script in the after job routine.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Here, Ray created something like this a while back. Take a look
viewtopic.php?t=101158.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

I can go for After Job routine. How do I get the size of the file. o/s is Windows. Secondly, I am finding 2kb file size even though no records are written to the file.. it's containing the column names of the file (.csv)
dsx
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You can go to the sequential file stage properties and uncheck "First line is column names" option. That will truely keep the file empty if its empty.
Look at Rays routine. He is using the STATUS function to determine the file size. STATUS() function returns different information in a dynamic array. The size info is present in the 6th entry in the array.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

I need to have the column names in the file.
dsx
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

well then instead of checking for 0 bytes, check for 2kb. And if a file is 2kb or less, then delete it.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

DSguru2B,

Please let me know, where do I find Status function created by Ray to determine the file size.
dsx
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

If you click the link provided by DSGuru in one of his earlier posts, it will lead you to that thread where in second page you can find a routine written by Ray. I remember doing something similar in one of my earlier projects but I can't dig that routine at the moment. It's possible when I get back home and shall try doing that.
Kris

Where's the "Any" key?-Homer Simpson
Post Reply