Appending to a Sequential 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

Post Reply
asitagrawal
Premium Member
Premium Member
Posts: 273
Joined: Wed Oct 18, 2006 12:20 pm
Location: Porto

Appending to a Sequential File

Post by asitagrawal »

Hi,

I am trying to open, read and append to an existing sequentila file.
Below is the code I am trying to use.

Code: Select all

OpenSeq "C:\FileTest\Test.txt" To MyFile 
Then
  Call DSLogInfo("MB Successfuly Opened File","FileTest")
  WriteSeq "First Line" to MyFile  

     Then
     WeofSeq MyFile
     Call DSLogInfo("MB Success Writing To File":Status(),"FileTest")
     CloseSeq MyFile
     Ans = 0
     End 
     Else
       Call DSLogInfo("MB Error Writing To File, status = ":Status(),"FileTest")
       Call DSLogFatal("MB Error Writing To File","FileTest")
       GoTo ErrExit
     End
End
Else  
Call DSLogWarn("MB Error Opening File, status ":Status(),"FileTest")
ErrExit:
CloseSeq MyFile
Ans = 1
End
But it is not appending the text, :(

As suggested in the Developer's Guide, I am writing the WeofSeq immediately, which shifts the pointer to next line.

Plz suggest.
Regards.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

The WEOFSEQ writes an EOF (end-of-file) at the current location, truncating the file. And your WRITESEQ statement won't work the way you expect it either, as the file pointer is at the beginning of the file after you open it.

You need to put a

Code: Select all

SEEK MyFile 0,2
after your open to position to the end of file.
asitagrawal
Premium Member
Premium Member
Posts: 273
Joined: Wed Oct 18, 2006 12:20 pm
Location: Porto

Post by asitagrawal »

Hi,

I tried to use this modified code , to shift the pointer to new line and continue writing... but now the loop exits at encountering the EOF and does not go to WriteFile...

Code: Select all

OpenSeq "C:\FileTest\Test.txt" To MyFile 
Then
  Call DSLogInfo("MB Successfuly Opened File","FileTest")
ReadSeq Dummy From MyFile 
Then
LOOP  
WHILE Status() ne 1
  ReadSeq Dummy From MyFile 
  UNTIL ( Status() ne 1 )
REPEAT
  Call DSLogInfo("MB Reached EOF, status ":Status(),"FileTest")
  Goto WriteFile
End
Else 
Call DSLogWarn("MB Error Reading 1 File, status ":Status(),"FileTest")
Goto ErrExit
End

LOOP  
WHILE Status() ne 1
  ReadSeq Dummy From MyFile Else Goto ErrReading;
  UNTIL ( Status() ne 1 )
REPEAT
  Call DSLogInfo("MB Reached EOF, status ":Status(),"FileTest")
  Goto WriteFile

ErrReading:
    Call DSLogWarn("MB Error Reading File, status ":Status(),"FileTest")
    Goto ErrExit

WriteFile:
  WriteSeq InputText to MyFile  
     Then
     WeofSeq MyFile
     Call DSLogInfo("MB Success Writing EOF To File":Status(),"FileTest")
     Call DSLogInfo("MB Success Writing To File":Status(),"FileTest")
     CloseSeq MyFile
     Ans = 0
     End 
     Else
       Call DSLogInfo("MB Error Writing To File, status = ":Status(),"FileTest")
       Call DSLogFatal("MB Error Writing To File","FileTest")
       GoTo ErrExit
     End

End

Else  
Call DSLogWarn("MB Error Opening File, status ":Status(),"FileTest")

ErrExit:
CloseSeq MyFile
Ans = 1


End
Please guide...
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What are you trying to accomplish here? :?

Seems that you took an issue with a simple solution - the change that Arnd posted - and made things way more complicated than they need to be. You just needed his one command to reset the file pointer to the EOF so you could append, there's no need to read all of the records to get there.

How about spelling out - in words - what this routine is supposed to do.
-craig

"You can never have too many knives" -- Logan Nine Fingers
asitagrawal
Premium Member
Premium Member
Posts: 273
Joined: Wed Oct 18, 2006 12:20 pm
Location: Porto

Post by asitagrawal »

Thx a lot...
I think I missed that command..
I used SEEK to shift the pointer to EOF..

and I exaclty wanted the same i.e Appending to an existing file..


Thx a lot to all.. :)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

All that trouble, when you could have downloaded the OpenSequentialFile routine!
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply