Page 1 of 1

Reading and Writing to same sequential file

Posted: Tue Jan 26, 2010 9:28 am
by naren6876
Hi,

I am trying to Read and Write to same sequential file (i am overwriting the sequential file on Target side). But it fails as it is not reading from the file.

But my observation is, if i change the filename on the target side it is reading data from the file and writing to new file.

Any help would be highly appreciated.

Thanks,
naren

Posted: Tue Jan 26, 2010 9:35 am
by chulett
What help do you need? You cannot write back to the same file you are reading from, doesn't matter what tool we're talking about. Think about what you are asking it to do when overwriting the target.

Re: Reading and Writing to same sequential file

Posted: Tue Jan 26, 2010 6:53 pm
by vivekgadwal
naren6876 wrote:Hi,

I am trying to Read and Write to same sequential file (i am overwriting the sequential file on Target side). But it fails as it is not reading from the file.

But my observation is, if i change the filename on the target side it is reading data from the file and writing to new file.

Any help would be highly appreciated.

Thanks,
naren
It is quite obvious that once you open a file, you can write to it. You just try doing it manually on a Windows machine and see if you can do it. If you cannot, then this would extend to the tool too.
A solution to your problem is to write to another file and use another job OR a Unix command to rename the file back to the original name.

Posted: Wed Jan 27, 2010 12:26 am
by ReachKumar
Yes you can use Unix command to rename the Target file to the Source file in the after job sub routine property of Data Stage job.

Posted: Wed Jan 27, 2010 2:15 am
by ray.wurlod
... but not on a Windows server unless there's some kind of UNIX emulator, such as MKS Toolkit, available.

Posted: Wed Jan 27, 2010 8:02 am
by PhilHibbs
If what you want to do is read all the data in from a file, apply some processing, and then write the data back out to the file, then that isn't really what DataStage jobs do. They don't hold data sets in memory, they typically process just one row at a time. You need to store the data somewhere while the transformation is being applied, and then write it back to the original file afterwards.

You can read the original file, pass through a Transformer, back out to a temporary file, and then have another link coming out of the temporary file and in to another Sequential File with the original name. That will do what you want to do in one job, but does involve landing the data into a temporary file. Or you can do the delete/rename thing mentioned by others.