The Close File using CLF (CLOFCLF) command closes a file previously opened with the Open File using CLF (OPNFCLF) command.
If the file is not currently open CLOFCLF will send the diagnostic message VC25009. There will be no escape message sent for this situation.
The CLOFCLF command can be run outside of a compiled program. This direct command entry capability may be beneficial in situations where a file was not closed within an application program due to an application error.
Restrictions:
- Input/Output operations to a CLF shared file open should not be run concurrently among threads in a job. A shared file open is one where the OPNPGM parameter has been specifed with a value other than *CURPGM. If application thread serialization is used CLF shared files will utilize a common I/O feedback information area.
File identifier (FILEID)
Specifies the file identifier that was used on a previous Open File using CLF (OPNFCLF) command in the application.
This parameter is used by CLF commands to identify the file to be processed by the command.
This is a required parameter.
- simple-name
- Specify a name that matches the FILEID parameter value of a previous OPNFCLF command.
Program opening file (OPNPGM)
The same FILEID value can be in use across multiple programs within a job. Each instance of a file open is uniquely identifed by the OPNPGM parameter. This parameter specifes the application program that initially opened the file using the Open File using CLF (OPNFCLF) command.
All CLF commands that reference the same FILEID and OPNPGM combination share the same view of the file. If one program causes the position within the file to change all programs see that change. If one program closes the file then the file is closed to all programs.
The combination of FILEID and OPNPGM must be unique within the activation group the application program is running in.
If the program name is *CURPGM then the library qualifier for this parameter is ignored. The library of the current program will be used.
Single values: Program opening file
- *CURPGM
- The current program opened the file associated with FILEID. It is this file open instance that is to be used.
Qualifier 1: Program opening file
- name
- Specify the name of the program that initially opened the file identified by FILEID. It is this file open instance that is to be used.
Qualifier 2: Library
- *CURLIB
- The current library for the thread is used. If there is no current library for the thread then library QGPL is used.
- name
- Specify the name of the library where the program that initially opened the file is located.
Examples for CLOFCLF
Example 1: Closing a File
CloFCLF FileID(DPT)
This command closes the file identified by a FILEID of DPT. The file must have been previously opened in the same program that is using the CLOFCLF command.
Example 2: Closing a FILEID Shared Across Programs
This example includes two programs. The first program, DEV_SHROPN, opens the VC2EMP database file for input processing and reads one record. The second program, DEV_SHRCLO, reads one record from the open FILEID of DEV_SHROPN and then closes the file. The record read by DEV_SHRCLO is actually the second record of the VC2EMP file as it's position in the file is determined by the last user of the shared FILEID -- DEV_SHROPN> When DEV_SHRCLO returns to DEV_SHROPN, the VC2EMP file is also closed for DEV_SHROPN.
Pgm
/***********************************************/
/* Declare the Employee master file VC2EMP and */
/* indicators used with CLF I/O Commands */
/***********************************************/
DclFCLF FileID(VC2EMP)
DclIndCLF CLFInd(*Yes)
/***********************************************/
/* Open the Employee master file VC2EMP in */
/* arrival sequence */
/* Read the first record in the file */
/* Send a message showing what record was read */
/***********************************************/
OpnFCLF FileID(VC2EMP) ERR(&ERR)
If Cond(&ERR) Then(Do)
SndPgmMsg Msg( +
'Error doing shared open from DEV_SHROPN')
Return
EndDo
ReadRcdCLF FileID(VC2EMP)
SndPgmMsg Msg('DEV_SHROPN found' *BCat &EmpFName)
/***********************************************/
/* Call the DEV_SHRCLO example program. */
/* */
/* DEV_SHRCLO will use the open of VC2EMP */
/* performed in this program and, after */
/* reading one record, close VC2EMP */
/***********************************************/
Call Pgm(DEV_SHRCLO)
/***********************************************/
/* Upon return from DEV_SHRCLO attempt to read */
/* the next record from the VC2EMP file. */
/* */
/* An error should be returned from READRCDCLF */
/* as VC2EMP has been closed. */
/* The program will send a message based on */
/* the &ERR indicator returned by READRCDCLF */
/***********************************************/
ReadRcdCLF FileID(VC2EMP) ERR(&ERR)
If Cond(*Not &ERR) Then(SndPgmMsg +
msg('DEV_SHRCLO did not close VC2EMP'))
Else Cmd(SndPgmMsg Msg( +
'The file was closed by DEV_SHRCLO'))
/***********************************************/
/* The program now returns. */
/* */
/* DEV_SHROPN could use the CLOFCLF command */
/* to close the file even though it is not */
/* open. Closing a file that is not open */
/* will result in a diagnostic message, but */
/* not a severe error. */
/***********************************************/
EndPgm
The source for this example can be found in member DEV_SHROPN of source file VC2CLSRC in library VC2CLF. The source for physical file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF.
To compile this example you can use the command
CrtBndCLF Pgm(VC2CLF/DEV_SHROPN) SrcFile(VC2CLF/DEV_SHROPN)
This example program does need to be compiled into the VC2CLF library as that library name is hardcoded in program DEV_SHRCLO for the OPNPGM keyword of several CLF commands.
Pgm
/***********************************************/
/* Declare the Employee master file VC2EMP and */
/* CLF-related indicators */
/***********************************************/
DclFCLF FileID(VC2EMP)
DclIndCLF CLFInd(*Yes)
/***********************************************/
/* Open the VC2EMP file using the open */
/* done in VC2CLF/SHROPN */
/***********************************************/
OpnFCLF FileID(VC2EMP) OpnPgm(VC2CLF/DEV_SHROPN) +
ERR(&ERR)
If Cond(&ERR) Then(Do)
SndPgmMsg Msg( +
'Error doing shared open from DEV_SHRCLO')
Return
EndDo
/***********************************************/
/* Read the next record from VC2EMP. */
/* */
/* As DEV_SHROPN read one record (Rebecca) */
/* this read should be the second record */
/* in arrival sequence (Bruce) */
/* The program sends a message showing what */
/* record was read */
/***********************************************/
ReadRcdCLF FileID(VC2EMP) OpnPgm(VC2CLF/DEV_SHROPN)
SndPgmMsg Msg('DEV_SHRCLO found' *BCat &EmpFName)
/***********************************************/
/* DEV_SHRCLO now closes the file initially */
/* opened by VC2CLF/SHROPN. This also */
/* closes the file for VC2CLF/SHROPN */
/***********************************************/
CloFCLF FileID(VC2EMP) OpnPgm(VC2CLF/DEV_SHROPN)
EndPgm
The source for this example can be found in member DEV_SHRCLO of source file VC2CLSRC in library VC2CLF. The source for physical file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF.
To compile this example you can use the command
CrtBndCLF Pgm(VC2CLF/DEV_SHRCLO) SrcFile(VC2CLF/VC2CLSRC)