From Br Wiki
Jump to: navigation, search

The Close (CL) statement deactivates access to a data or window file for input or output. It may also be used to Drop or Free a file.

Comments and Examples

The functions of the Close statement are identical for display, internal and external files.

Line 9100 is an ordinary Close statement:

9100 CLOSE #1:

Line 6000 frees the file as it closes it and transfers control to 9300 if the IOErr error condition occurs:

6000 CLOSE #2,FREE:  IOERR 9300

When used with a window file, Close ends access to the window and causes the information which was behind the window to be redisplayed.

In the following example, the field created by the Print Fields statement in line 30 is retained by the window opened in line 40. Upon closing of the file (line 60), the field created by line 30 is redisplayed:

00030 PRINT FIELDS "3,14,C 18,R":"Original contents"
00050 PRINT #1,FIELDS "6,14,C 18,R":"New contents"
00060 CLOSE #1:

In many situations -particularly in the use of overlapping windows -the capability of restoring some or all of a screen in this manner is desirable. To avoid restoring the original contents of a window, you can include either the Drop or Free keywords in the Close statement. This closes the window without altering the current display.


CLOSE {#<file number>|#<window number>} [,FREE]|[,DROP] [,RELEASE]:[<Error Condition> <line ref>][,...]



  1. When closing a data file, keep the file and all data intact. When closing a window file, restore the original contents of the screen.
  2. Leave PROTECT RESERVE specifications active.
  3. Interrupt the program if an error occurs and ON is not active.


Either the "file-num" or the "wind-num" parameter must be used to identify the file to be closed. It must be preceded by a pound (#) symbol.

Like the Drop command, the optional "Drop" parameter empties the contents of a file. The file must be opened NoShr for this parameter to be used.

Like the FREE command, the optional "FREE" parameter erases a file from the system. The file must be opened NOSHR for this parameter to be used.

The "RELEASE" parameter releases a file, which has been locked with the OPEN statement, RESERVE parameter. The only other ways that a locked file can be released is with the PROTECT command RELEASE parameter or by exiting the workstation.

CLOSE allows error processing with the optional "error-cond line-ref" parameter. See Error Conditions for more information.

Technical Considerations

  1. Relevant error conditions are: EOF, ERROR, Exit, and IOERR.
  2. If no Close statements are included, an automatic CLOSE of all files occurs (in reverse order from which they were opened) at the end of the program. The exception to this is when the program ends with a CHAIN statement, which uses the optional "FILES" parameter to override the CLOSE.
  3. An important function of the CLOSE statement (whether explicitly coded or implicitly done by the system) is making sure that the last records in data buffers are written to the file and that the internal file's header record is updated. Close protects data when a diskette is removed before the execution of a Close, End, Stop, or Chain (without the FILES parameter).