File Handling

Although a WFL job cannot read from or write to files itself, it provides considerable control over the files that programs initiated through WFL can read from or write to. The main tool that provides this control is file equation, which is discussed under Task Initiation earlier in this section. In addition, there are several statements available in WFL that provide even more flexibility in file handling.

File Handling Statements

Files can be opened in WFL by using the OPEN statement. The file specified in this statement is opened with the I/O capabilities specified in the NEWFILE attribute, FILEUSE attribute, or other attributes of the file. If the NEWFILE attribute or the FILEUSE attribute is not assigned, an attempt is made to open the specified file for both input and output. Refer to the File Attributes Programming Reference Manual for more information about file attributes.

The following table lists five statements that close files in different ways.

Statement

Result

CRUNCH

Closes and releases a file, and returns the unused portion of the last row of the file to the system. Once a file is crunched, it takes up less space, but can no longer be expanded. This statement is used for disk files only.

LOCK

Closes, releases, and locks a file. If the file is a disk file, it is kept as a permanent file on disk. If the file is a tape file, the tape is rewound and unloaded, making the unit inaccessible to the system until it is readied again manually.

PURGE

Removes a file and frees the area it was occupying for reuse.

RELEASE

Closes and releases a file.

REWIND

Closes a file and rewinds it. For a tape file, this means that the tape is rewound. For a disk file, the record pointer is reset to the first record of the file.

A WFL job can interrogate the attributes of a file. To do this, the file must first be declared in the job with certain minimal attributes specified. In addition, the file must be opened.

Examples

The following job examines a file to determine whether it is a COBOL74 or COBOL85 file, and chooses the corresponding compiler:

?BEGIN JOB COBOLCOMP(STRING SYMBOL); 
  FILE SYMBOLF; 
  STRING COMPNAME; 
  SYMBOLF (TITLE=#SYMBOL,KIND=DISK,NEWFILE=FALSE, 
           DEPENDENTSPECS=TRUE); 
  OPEN (SYMBOLF); 
  IF SYMBOLF (FILEKIND) = "COBOL74SYMBOL" THEN 
    COMPNAME := "COBOL74" 
  ELSE 
    COMPNAME := "COBOL85"; 
  COMPILE OBJECT/#SYMBOL WITH #COMPNAME LIBRARY GO; 
    COMPILER FILE CARD (TITLE=#SYMBOL,KIND=DISK); 
?END JOB. 

The following subroutine uses the file opening and closing capabilities of WFL to create dummy files (empty files that can be used to indicate that some particular event has occurred in the job). Because subroutines cannot contain file declarations, file F is declared globally.

SUBROUTINE MAKE(STRING FILENAME); 
BEGIN 
  F (TITLE = #FILENAME, KIND = DISK, NEWFILE = TRUE); 
  OPEN (F); 
  LOCK (F); 
END MAKE;  

Refer to Job Restart After a Halt/Loadfor an example of why you might want to use a job to create dummy files.