Working with files in CL programs or procedures
Two types of files are supported in CL procedures and programs: display files and database files.
You can send a display to a workstation and receive input from the workstation for use in the procedure or program, or you can read data from a database file for use in the procedure or program.
To use a file in a CL procedure or program, you must:
- Format the display or database record, identifying fields and conditions which you enter as DDS source. The use of DDS is not required for a database file.
- Create the file using the Create Display File (CRTDSPF) command, Create Physical File (CRTPF) command, or Create Logical File (CRTLF) command. Subfiles (except for message subfiles) are not supported by CL procedures and programs.
- For database files, add a member to the file using the Add Physical
File Member (ADDPFM) command or
command. This is not required if a member was added by the CRTPF or CRTLF commands. The file must have a member when the procedure or program is processed, but does not need to have a member when the procedure or program is created.Add Logical File Member (ADDLFM)
- Refer to the file in the CL procedure using the DCLF command, and refer to the record format on the appropriate data manipulation CL commands in your CL source.
- Create the CL module.
- Create the program or service program.
Up to five display or database files can be referred to in a CL procedure. The support for database files and display files is similar as the same commands are used. However, there are a few differences, which are described here.
- The following statements apply only to database files used with CL procedures
and programs:
- Only database files with a single record format may be used by a CL procedure or program.
- The files may be either physical or logical files, and a logical file may be defined over multiple physical file members.
- Only input operations, with the RCVF command, are allowed. The WAIT and DEV parameters on the Receive File (RCVF) command are not allowed for database files. In addition, the SNDF, SNDRCVF, and ENDRCV commands are not allowed for database files.
- DDS is not required to create a physical file which is referred to in a CL procedure or program. If DDS is not used to create a physical file, the file has a record format with the same name as the file, and there is one field in the record format with the same name as the file, and with the same length as the record length of the file (RCDLEN parameter of the CRTPF command).
- The file need not have a member when it is created for the module or program. It must, however, have a member when the file is processed by the program.
- The file is opened for input only when the first Receive File (RCVF) command is processed. The file must exist and have a member at that time.
- The file remains open until the procedure or original program model (OPM) program returns or when the end of file is reached. When end of file is reached, message CPF0864 is sent to the CL procedure or program, and additional operations are not allowed for the file. The procedure or program should monitor for this message and take appropriate action when end of file is reached.
- The following statements apply only to display files used with CL procedures
and programs:
- Display files may have up to 99 record formats.
- All data manipulation commands (SNDF, SNDRCVF, RCVF, ENDRCV and WAIT) are allowed for display files.
- The display file must be defined with the DDS.
- The display file is opened for both input and output when the first SNDF, SNDRCVF, or RCVF command is processed. The file remains open until the procedure or OPM program returns.
The format for the display is identified as a record format in DDS. Each record format may contain fields (input, output, and input/output), conditions/indicators, and constants. Several record formats can be entered in one display file. The display file name, record format name, and field names should be unique, because other high-level languages (HLLs) may require it, even though CL procedures and programs do not.