Kbase P101334: How to flush a stream opened for output in the ABL.
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/15/2008 |
|
Status: Unverified
GOAL:
How to flush a stream opened for output in the ABL.
GOAL:
How to force buffered data to be flushed into the output file.
FIX:
The ABL allows to write to a file on disk in buffered or unbuffered fashion (the default being buffered).
When writing to file in buffered fashion, there is no specific ABL instruction to flush the content of memory buffers to disk.
The SEEK instruction, though, has the side effect of flushing any output kept in memory before seeking to the new position. This side effect can be exploited to our advantage.
Using the SEEK instruction with the TO END option has the side effect of flushing the output buffers, without changing the current write position into the output file.
SEEK { INPUT | OUTPUT | STREAM stream } TO END
For example:
DEFINE STREAM myOutput.
OUTPUT STREAM myOutput TO mySampleFile.txt.
PUT STREAM myOutput
"This text is too short to be written to disk" SKIP
"with 'normal' buffered output." SKIP
.
PAUSE MESSAGE "Look at mySampleFile.txt, it will be 0 bytes.".
SEEK STREAM myOutput TO END.
PAUSE MESSAGE "Look at mySampleFile.txt, it will contain text now.".
PUT STREAM myOutput
"Further output data will be appended at the end" SKIP
"of the file, as usual..."
.
OUTPUT STREAM myOutput CLOSE.