Open and close files in a CL procedure

When you use CL support, the file referred to is implicitly opened when you do your first send, receive, or send/receive operation. An opened display file remains open until the procedure or OPM program in which it was opened returns or transfers control. An opened database file is closed when end of file is reached, or when the procedure or OPM program in which it was opened returns or transfers control. Once a database file has been closed, it cannot be opened again during the same call of the procedure or OPM program.

When a database file opens, the first member in the file will open, unless you previously used an Override Database File (OVRDBF) command to specify a different member (MBR parameter). If a procedure or OPM program ends because of an error, the files close. A file remains open until the procedure or OPM program in which that file was opened ends. Because of this, you have an easy way to share open data paths between running procedures and programs. You can open a file in one procedure or program. Then the file can share its open data path with another procedure or program under either of the following conditions:

You can share files in this way between any two procedures or programs. Use online help for a detailed description of the function available when the system shares open data paths. Additionally, IBM® provides a description of the SHARE parameter on the Create Display File (CRTDSPF), Create Physical File (CRTPF), and Create Logical File (CRTLF) commands online. A display file opened in a CL procedure or OPM program always opens for both input and output. A database file opened in a CL procedure or OPM program opens for input only.

Do not specify LVL(*CALLER) on the Reclaim Resources (RCLRSC) command in CL procedures and programs using files. If you specified LVL(*CALLER), all files opened by the procedure or OPM program would be immediately closed, and any attempt to access the file would end abnormally.