5.7. Closing a Stream

As already mentioned, REXX does not have an explicit way of
opening a stream. Nor does it have an explicit way of closing a
stream. There is one semi-standard method: If you call LINEOUT(),
but omit both the data to be written and the new current write
position, then the implementation is defined to set the current
write position to the end-of-file.  Furthermore, it is allowed by
TRL to do something “magic” in addition. It is not explicitly
defined what this magic is, but TRL suggests that it may be
closing the stream, flushing the stream, or committing changes
done previously to the stream.

In SAA, the definition is strengthened to state that the “magic”
is closing, provided that the environment supports that operation.

A similar operating can be performed by calling CHAROUT() with
neither data nor a new position. However, in this case, both TRL
and SAA leave it totally up to the implementation whether or not
the file is to be closed. One can wonder whether the changes for
LINEOUT() in SAA with respect to TRL should also have been done to
CHAROUT(), but that this was forgotten.

TRL2 does not indicate that LINEIN() or CHARIN() can be used to
close a string. Thus, the closest one gets to a standard way of
closing input files is to call e.g. LINEOUT(); although it is
conceptually suspect to call an output routine for an input file.
The historical reasons for this omission are perhaps that flushing
output files is vital , while the concept of flushing is
irrelevant for input files; flushing is an important part of
closing a file, and that explains why closing is only indicated
for output files.

Thus, the statement:

     call lineout ‘myfile.txt’

might be used to close the stream myfile.txt in some
implementations. However, it is not guaranteed to close the
stream, so you cannot depend on this for scripts of maximum
portability, but it’s better than nothing. However, note that if
it closes the stream, then also the current read position is
affected. If it merely flushes the stream, then only the current
write position is likely to be affected.




PREV NEXT