CLOSE (Close Files)

Free-Form Syntax CLOSE{(E)} file-name|*ALL
Code Factor 1 Factor 2 Result Field Indicators
CLOSE (E)   file-name or *ALL   _ ER _

The explicit CLOSE operation closes one or more files or devices and disconnects them from the module. The file cannot be used again in the module unless you specify an explicit OPEN for that file. A CLOSE operation to an already closed file does not produce an error.

file-name names the file to be closed.

You can specify the keyword *ALL to close all files defined on global File specifications at once. Specifying CLOSE *ALL in a subprocedure does not have any effect on local files in the subprocedure. To close all the local files in a subprocedure, you must code a separate CLOSE operation for each file. You cannot specify an array or table file (identified by a T in position 18 of the file description specifications).

To handle CLOSE exceptions (file status codes greater than 1000), either the operation code extender 'E' or an error indicator ER can be specified, but not both. For more information on error handling, see File Exception/Errors.

Positions 71, 72, 75, and 76 must be blank.

If an array or table is to be written to an output file (specified using the TOFILE keyword) the array or table dump does not occur at LR time if the file is closed by a CLOSE operation). If the file is closed, it must be reopened for the dump to occur.

For more information, see File Operations.

Figure 1. CLOSE Operation
 *..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
 *  The explicit CLOSE operation closes FILEB.

 /FREE
    CLOSE FILEB;
 
      //  The CLOSE *ALL operation closes all files in the
      //  module. You must specify an explicit OPEN for any file that
      //  you wish to use again.  If the CLOSE operation is not
      //  completed successfully, %ERROR returns '1'.
 
    CLOSE(E) *ALL;
 
 /END-FREE