Using Files


CL programs are weak in file processing. In fact, CL programs can only process three types of files: database, source, and display.

Database and source files can only be read (never written to) by a CL program. CL lacks the ability to write new records, update existing ones, or delete records.

Display files can be either read or written. CL doesn't support all display file features. For example, CL has no support for subfiles, except message subfiles.

Tip 

A CL procedure can process up to five files.

The DCLF Command

Before you process a file in CL, you must declare it using the DCLF command. The DCLF command must be placed at the beginning of the program, either before or after (or amid) the DCL commands.

The DCLF command has six parameters, three of which are discussed here. The FILE parameter identifies the file you want to process in the CL program. RCDFMT names the record formats you will use in the program. The parameter defaults to *ALL, and you should leave it alone until you understand more about record formats. The OPNID parameter allows you to specify an open file identifier by which this file is known in other commands throughout the procedure.

The DCLF command retrieves the external definition of the file and creates CL variables using the DDS names prefixed with the ampersand (&) symbol. For example, if the file has a variable called INPUT, the DCLF command creates a CL variable called &INPUT with the same type and length as defined in the DDS of the file.

Tip 

If the file was not created with DDS (i.e., if it is a "flat" file), the DCLF command creates a single character variable equal in length to the record in the file and named the same as the file. For example, if the file is called MASTER, DCLF creates a CL variable called &MASTER

Display file indicators also become CL variables. Their names are &INXX, where xx is the indicator number. For example, if a display file uses indicator 03, the DCLF command creates a CL variable named &IN03, which will be declared as TYPE(*LGL) [logical].

If the OPNID parameter is used, the variable names have a slightly different format. Variable names begin with ampersand, followed by the open file identifier, an underscore, and the field name. The CL variable created for field ID in file MASTER, which has the open file identifier M, is &M_ID.

Other Commands

CL provides three commands to process files record by record:

  • RCVF. The Receive File command reads a record from the file. If no more records are in the file, the RCVF command ends with *ESCAPE message CPF0864. If you are processing a display file, you must indicate the name of the record format you are reading from, if more than one is present.

  • SNDF. The Send File command writes a record to the file. You can use SNDF only on display files, and you must indicate the name of the record format you are writing, if more than one is present.

  • SNDRCVF. The Send/Receive File writes a record and then reads it back. Like SNDF, it can be used only on display files, and you must specify the name of the record format to process, if more than one is present.



IBM i5/iSeries Primer(c) Concepts and Techniques for Programmers, Administrators, and Sys[... ]ators
IBM i5/iSeries Primer(c) Concepts and Techniques for Programmers, Administrators, and Sys[... ]ators
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 245

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net