Closing a database file
When your program completes processing a database file member, it should close the file. Closing a database file disconnects your program from the file.
The close operation releases all record locks and all file member locks, forces all changes made through the open data path (ODP) to auxiliary storage, then destroys the ODP. (When a shared file is closed but the ODP remains open, the functions differ) To close a database file in a program, use one of the following methods:
- High-level language close statements
Most high-level languages allow you to specify that you want to close your database files. For more information about how to close a database file in a high-level language program, see your high-level language topic collection.
- Close File (CLOF) command
You can use the CLOF command to close database files that were opened using either the Open Database File (OPNDBF) or Open Query File (OPNQRYF) command.
- Reclaim Resources (RCLRSC) command
The RCLRSC command releases all locks (except, under commitment control, locks on records that were changed but not yet committed), forces all changes to auxiliary storage, then destroys the ODP for that file. You can use the RCLRSC command to allow a calling program to close the files of a called program. (For example, if the called program returns to the calling program without closing its files, the calling program can then close the files of the called program.) However, the normal way of closing files in a program is with the high-level language close operation or through the CLOF command. For more information about resource reclamation in the integrated language environment, see the ILE Concepts book.
If a job ends normally (for example, a user signs off) and all the files associated with that job were not closed, the system automatically closes all the remaining open files associated with that job, forces all changes to auxiliary storage, and releases all record locks for those files. If a job ends abnormally, the system also closes all files associated with that job, releases all record locks for those files, and forces all changes to auxiliary storage.
When a process is trying to lock a file that is held by another process, the Close database file exit program is called. This exit is called in the process that is holding the lock.
Parent topic:
Processing database files
Related concepts
Sharing database files in the same job or activation group
Control language
Related reference
Close File (CLOF) command
Reclaim Resources (RCLRSC) command