I am trying to write a message to log file(sequential file) using a server routine which called as after job subroutine. I want to append log to an existing file. how can i achieve this? I tried with combination of openpath & write but it only overwrites. Help needed..pls...
thanx in advance
How to append to an existing sequential file using routine?
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 28
- Joined: Thu Mar 13, 2008 11:24 pm
This will work.
Code: Select all
OPENSEQ FilePath:FileName TO LogFile ON ERROR Ans = -1
THEN
LOOP
READSEQ DummyVar FROM LogFile
THEN
stat=STATUS()
END
ELSE
EXIT
END
WHILE stat<>1 REPEAT
WRITESEQ
Ping me if I am wrong...
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Yuk!
Use SEEK to get to end of file quickly, don't read through the file.
OpenSeq can take its Else clause even if the file is open for writing - you must also accommodate this possbility.
Search the forum for a Routine called OpenSequentialFile that takes all the hard work out of it.
And you must, must, must use CloseSeq to close a file opened for sequential access with OpenSeq, so that the exclusive lock set by OpenSeq can be released.
Use SEEK to get to end of file quickly, don't read through the file.
OpenSeq can take its Else clause even if the file is open for writing - you must also accommodate this possbility.
Search the forum for a Routine called OpenSequentialFile that takes all the hard work out of it.
And you must, must, must use CloseSeq to close a file opened for sequential access with OpenSeq, so that the exclusive lock set by OpenSeq can be released.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Ok. Here is the modified code.
Yuk?
Ray I am still a beginner. Anyway thanks for the pointer. Any more Yuks, improvements?
Code: Select all
OpenSeq FilePath : FileName To TempFile On Error Ans = "Not Able to open file"
Then
Seek TempFile , 0, 2
THEN
WriteSeq Message to TempFile Then Ans = "Success"
End
End
CloseSeq TempFile
![Embarassed :oops:](./images/smilies/icon_redface.gif)
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Code: Select all
OpenSeq FilePath : FileName To TempFile
On Error
Ans = "Error (code " : Status() : ") opening file."
End
Locked
Ans = "File in use by user number " : Status()
End
Then
* File exists and opened. Need to position to EOF.
Seek TempFile , 0, 2
Then
WriteSeq Message to TempFile Then Ans = 0
End
End
Else
If Status() = 0
Then
* File does not exist but is open for writing.
* The write operation will bring the file into existence.
WriteSeq Message To TempFile Then Ans = 0
End
End
If FileInfo(TempFile,0) Then CloseSeq TempFile
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.