Close Database File (CLOSE)

The Close Database File (CLOSE) command will explicitly close a database file that was implicitly opened by a Receive File (RCVF) command run within the same CL program or ILE CL procedure. A file with the same open identifier must have been declared by a Declare File (DCLF) command within the same CL program or ILE CL procedure.

After the CLOSE command is run, the next RCVF command for this file will implicitly reopen the file and read a record from the file.

You can use CLOSE for a database file that is already closed or was never opened; no error message will be sent.

Restrictions:

Parameters

Keyword Description Choices Notes
OPNID Open file identifier Simple name, *NONE Optional

Open file identifier (OPNID)

Specifies the open file identifier that was declared on a preceding Declare File (DCLF) command in the same CL program or ILE CL procedure. A CL variable cannot be specified for this parameter value.

*NONE
No open file identifier is provided. This command will use the file associated with the DCLF command that had *NONE specified for the OPNID parameter. Only one file can be declared in a CL program or ILE CL procedure with *NONE as the open file identifier.
simple-name
Specify a name that matches the OPNID parameter value on a preceding DCLF command in the same CL program or ILE CL procedure.

Examples

Example 1: Close a Database File Declared with No Open Identifier

DCLF   FILE(MYLIB/MYFILE1)
  :
RCVF
  :
CLOSE
RCVF

This CLOSE command explicitly closes database file MYFILE1 located in library MYLIB. The DCLF, RCVF, and CLOSE commands did not specify an open identifier (OPNID parameter) so a default open identifier of *NONE was used. The first Receive File (RCVF) command implicitly opened file MYFILE1. Assuming the CLOSE command successfully closes the file, the second RCVF command would reopen the file and read a record from the file.

Example 2: Close a Database File Specifying an Open Identifier

DCLF   FILE(*LIBL/MYFILE2)  OPNID(FILE2)
  :
RCVF   OPNID(FILE2)
  :
CLOSE   OPNID(FILE2)
RCVF   OPNID(FILE2)

This CLOSE command explicitly closes database file MYFILE2 located in a library that is in the library list for the job. The DCLF, RCVF, and CLOSE commands that operate on this file must all specify the same open identifier (OPNID parameter) value. The first Receive File (RCVF) command implicitly opened file MYFILE2. Assuming the CLOSE command successfully closes the file, the second RCVF command would reopen the file and read a record from file MYFILE2.

Error messages

*ESCAPE Messages

CPF0777
File &1 in library &2 with open identifier &3 not closed.