WFL includes a number of expressions that can be used to interrogate the attributes of files. Depending on the type of attribute involved, these expressions might return integer, real, Boolean, or string values and can be used wherever that type of value is permitted in the job.
Expressions for File Attribute Inquiry lists all these expressions. Refer to Expressions for the syntax of each expression.
Table 4. Expressions for File Attribute Inquiry
File Attribute Type |
Expression Used |
---|---|
<Boolean file attribute> |
<Boolean file attribute primary> |
<file name file attribute> |
<string file attribute primary> |
<integer file attribute> |
<integer file attribute primary> |
<long file name file attribute> |
<string file attribute primary> |
<long title file attribute> |
<string file attribute primary> |
<mnemonic file attribute> |
<string file attribute primary> <file mnemonic comparison> |
<name file attribute> |
<string file attribute primary> |
<real file attribute> |
<real file attribute primary> |
<string file attribute> |
<string file attribute primary> |
<title file attribute> |
<string file attribute primary> |
KIND |
<string file attribute primary> |
SERIALNO |
The value of this attribute cannot be interrogated. |
In general, a file must have been declared in the job before its attributes can be interrogated. (The only exception is the file residence inquiry.) The syntax for file declarations is given in Declarations. The file should be declared with DEPENDENTSPECS set to TRUE, as described in Assigning File Attributes. Once the file is opened, the job can inquire about any of the attributes of that file.
File attribute inquiries have a wide variety of applications in WFL jobs. For example, the attributes of a file can be interrogated both before and after they are used by a task to see if the task altered the attributes. However, the task must be made to use a file that was declared in the job, because only the attributes of declared files can be interrogated. A global file assignment can be used to make the task use a file. (Global file assignment is described in File Equations.)
Another expression that is similar to a file attribute inquiry is the file residence inquiry, which checks on the residence of a file. This same information can be obtained by using a Boolean file attribute primary to interrogate the RESIDENT attribute of a file. However, the file residence inquiry has the advantage that it can be applied to files regardless of whether they were declared in the job. Refer to Expressions for more information on file residence inquiry.
Examples
The following example checks the length of a file by interrogating the value of the LASTRECORD attribute. The file is copied to tape and removed from disk if it is larger than 10,000 records.
OPEN (FILEA); I := FILEA (LASTRECORD) + 1; % LASTRECORD is 0-relative IF I GTR 10000 THEN BEGIN WAIT ("MOUNT TAPE NAMED FILETP FOR BACKUP",OK); COPY FILEA FROM ORDS (DISK) TO FILETP (TAPE) [T]; IF T(TASKVALUE) EQL 0 THEN REMOVE FILEA; END;
The value of LASTRECORD is the zero-relative sequence number of the last line of the file. Therefore, FILEA (LASTRECORD) + 1 returns the number of records in the file. Before the disk file FILEA is removed, the TASKVALUE of the copy task is checked to ensure that the copy was successful.
The security characteristics of a file can be inquired about through the SECURITYUSE, SECURITYTYPE, and SECURITYGUARD attributes, each of which returns a string value. For example:
IF FILEA (SECURITYUSE) NEQ "IO" THEN SECURITY #FILEA(TITLE) IO;
This statement can be used to ensure that a file enables both input and output.