CLOSE

Close a channel

WSupported on Windows
USupported on Unix
VSupported on OpenVMS
NSupported in Synergy .NET
CLOSE channel[, ...]

or

CLOSE channel THRU channel

channel

A channel to close. (n)

The CLOSE statement completes any pending I/O and terminates the association of a channel with its file or device.

When a channel is closed, all locks on the specified channel are released and the channel is available for future use. After a channel is closed, an I/O statement cannot reference that channel until an OPEN statement reactivates it.

If a channel is opened in output or update mode, any data contained in the system cache is output before the channel is released during a CLOSE. This ensures that any information written by the program is physically transferred to the device. The CLOSE statement saves the output file. If channel is not open, CLOSE returns without an error (it does nothing).

Note

The PURGE statement deletes the file opened on channel if the file is opened in output mode.

On OpenVMS, when you CLOSE a mailbox, EOF is written to the mailbox for compatibility with DIBOL. If you PURGE the channel, EOF is not written.

In Synergy .NET, make sure that you deterministically close channels. Waiting for the garbage collector to execute finalizers to close channels may cause problems with xfServer and cause channels to be closed automatically before your finalizer runs.

If you do not CLOSE a terminal channel in a program and output is still pending when the program stops, the output is discarded. This feature prevents the program from hanging forever when a Lat, Telnet, or modem control device has gone offline.

Tip

When using serial devices with modems attached, to avoid having your program hang on a CLOSE if the state of the port is unknown or hung, use PURGE in conjunction with the INITPORT subroutine and the GETS statement.

PURGE statement

open(TMPCHN, o, "test")                 ;Create test file
writes(TMPCHN, "Record 1")
writes(TMPCHN, "Record 2")
close TMPCHN                            ;Save test file
open(TMPCHN, i, "test")                 ;Open test file for input
reads(TMPCHN, testrec)                  ;Read first record
close TMPCHN                            ;Close channel
open(TMPCHN, o, "temp")                 ;Open temporary work file
write(TMPCHN, testrec, 13)              ;Write the 13th record
read(TMPCHN, testrec, 13)               ;Read record back in
purge TMPCHN                            ;Delete temporary work file and 
                                        ; close channel