Chapter 9
File-Handling Built-In Subroutines
In addition to the PL/I input and output statements and the functions and features available through the options of the ENVIRONMENT attribute, there are also several built-in file-handling subroutines. These subroutines invoke Record Management Services (RMS) procedures. They are called built-in subroutines because you do not need to declare them before using them in a PL/I program. These subroutines are summarized in Table 9.1, “Summary of File-Handling Built-In Subroutines” and are described individually in the following sections.
| Subroutine | Function |
|---|---|
| DISPLAY | Returns information about a file. |
| EXTEND | Allocates additional disk blocks for a file. |
| FLUSH | Requests the file system to write all buffers onto disk to preserve the current status of a file. |
| FREE | Unlocks all the locked records in a file. |
| NEXT_VOLUME | Begins processing the next volume in a multivolume tape set. |
| RELEASE | Unlocks a specified record in a file. |
| REWIND | Positions a file at its beginning or at a specific record. |
| SPACEBLOCK | Positions a file forward or backward a specified number of blocks. |
9.1. DISPLAY Built-In Subroutine
The DISPLAY built-in subroutine returns information about a specified file. Its calling sequence is as follows:
CALL DISPLAY (file-reference,variable-reference);
file-referenceSpecifies the file variable or constant for which information is to be obtained. If the file is not currently open, the DISPLAY subroutine implicitly opens the file with the attributes specified in the declaration of the file.
variable-referenceSpecifies the name of a structure variable into which information about the file is to be placed.
The format of the data returned by DISPLAY is defined in the data structure PLI_FILE_DISPLAY. This structure is declared in the text module PLI_FILE_DISPLAY in the default INCLUDE library PLI$STARLET (the PL/I compiler searches this library by default when it compiles a PL/I program). Each member of PLI_FILE_DISPLAY contains, on return from a call to DISPLAY, a value associated with the file for which information is requested. To refer to a value, you refer to the corresponding member name in the structure. Tables 9.2 through 9.4 summarize the members of the structure as follows:
Note
The PLI_FILE_DISPLAY structure has the same members for OpenVMS VAX and OpenVMS Alpha, but its format is different on each platform. The difference is due to the different alignment requirements of the two platforms.
You declare the structure PLI_FILE_DISPLAY with the BASED attribute; thus, to use this variable you must also declare a pointer variable to reference the structure and use an ALLOCATE statement to allocate storage for it before calling DISPLAY. For example:
%INCLUDE PLI_FILE_DISPLAY; DECLARE STATE_FILE FILE RECORD KEYED, FILEPTR POINTER; OPEN FILE(STATE_FILE); ALLOCATE PLI_FILE_DISPLAY SET (FILEPTR); CALL DISPLAY (STATE_FILE,FILEPTR->PLI_FILE_DISPLAY);
Following this call to DISPLAY, you can reference any of the members of FILEPTR->PLI_FILE_DISPLAY to determine information about the file STATE_FILE. The following statements use the EXPANDED_TITLE field to display the expanded file specification of STATE_FILE and the INDEXED and NUMBER_OF_KEYS fields to display the number of keys in the file:
PUT SKIP EDIT('File',FILEPTR->EXPANDED_TITLE, 'opened for input') (A,X,A,X,A); IF FILEPTR->INDEXED THEN PUT SKIP EDIT ('It is indexed with',FILEPTR->NUMBER_OF_KEYS,'keys') (A,X,A,X,A);
If you do not use the structure PLI_FILE_DISPLAY, as shown in this example, you must provide a structure that has the same declaration as PLI_FILE_DISPLAY. To obtain a copy of PLI_FILE_DISPLAY, use the LIBRARY command. For example:
$LIBRARY/TEXT/EXTRACT=PLI_FILE_DISPLAY/OUTPUT=FILESTRUC.PLI -$_SYS$LIBRARY:PLI$STARLET
Here, FILESTRUC.PLI is the name of the output file into which the LIBRARY command will copy PLI_FILE_DISPLAY.
Table 9.2, “ENVIRONMENT Option Values Returned by DISPLAY” summarizes the values returned by DISPLAY that correspond to ENVIRONMENT options and the data type of each structure member. For information on ENVIRONMENT options, see Chapter 7, Options of the ENVIRONMENT Attribute.
|
Member Name |
Data Type of Value Returned |
Meaning |
|---|---|---|
| APPEND | BIT(1) | APPEND option is enabled or disabled. |
| BACKUP_DATE | BIT(64) ALIGNED | Backup date of file (disk files only). |
| BATCH | BIT(1) | BATCH option is enabled or disabled. |
| BLOCK_BOUNDARY_FORMAT | BIT(1) | Records cannot cross block boundaries. |
| BLOCK_IO | BIT(1) | File is opened for block I/O. |
| BLOCK_SIZE | FIXED BIN | Block size of file (magnetic tape files only). |
| BUCKET_SIZE | FIXED BIN | Bucket size of file (disk files only). |
| CARRIAGE_RETURN_FORMAT | BIT(1) | Records have carriage return carriage control. |
| CONTIGUOUS | BIT(1) | CONTIGUOUS option is enabled or disabled. |
| CONTIGUOUS_BEST_TRY | BIT(1) | CONTIGUOUS_BEST_TRY option is enabled or disabled. |
| CREATION_DATE | BIT(64) ALIGNED | Creation date of file. |
| CURRENT_POSITION | BIT(1) | CURRENT_POSITION option is enabled or disabled. |
| DEFERRED_WRITE | BIT(1) | DEFERRED_WRITE option is enabled or disabled. |
| DELETE | BIT(1) | DELETE option is enabled or disabled. |
| EXPIRATION_DATE | BIT(64) ALIGNED | Expiration date of file. |
| EXTENSION_SIZE | FIXED BIN | Current extension size (disk files only). |
| FILE_ID | (6) FIXED BIN | File identification (disk files only). |
| FILE_SIZE | FIXED BIN | File allocation (disk files only). |
| FIXED_CONTROL_SIZE | FIXED BIN | Size of fixed-control area. |
| FIXED_LENGTH_RECORDS | BIT(1) | File has fixed-length records. |
| GROUP_PROTECTION | CHAR(4) VARYING | Protection for group members. |
| IGNORE_LINE_MARKS | BIT(1) | IGNORE_LINE_MARKS option is enabled or disabled. |
| INDEX_NUMBER | FIXED BIN | Current index number. |
| INDEXED | BIT(1) | File is or is not an indexed sequential file. |
| INITIAL_FILL | BIT(1) | INITIAL_FILL option is enabled or disabled. |
| MAXIMUM_RECORD_NUMBER | FIXED BIN | Relative file maximum relative record. |
| MAXIMUM_RECORD_SIZE | FIXED BIN | Largest record size. |
| MULTIBLOCK_COUNT | FIXED BIN | Multiblock count (disk files only). |
| MULTIBUFFER_COUNT | FIXED BIN | Multibuffer count. |
| NO_SHARE | BIT(1) | NO_SHARE option is enabled or disabled. |
| OWNER_GROUP | FIXED BIN | Group number of file's owner. |
| OWNER_MEMBER | FIXED BIN | Member number of file's owner. |
| OWNER_PROTECTION | CHAR(4) VARYING | Protection for file's owner. |
| RETRIEVAL_POINTERS | FIXED BIN | Number of mapping pointers. |
| PRINTER_FORMAT | BIT(1) | Records have printer carriage control. |
| READ_AHEAD | BIT(1) | READ_AHEAD option is enabled or disabled. |
| READ_CHECK | BIT(1) | READ_CHECK option is enabled or disabled. |
| RECORD_ID_ACCESS | BIT(1) | File is opened for access by record identification. |
| REVISION_DATE | BIT(64) ALIGNED | Revision date of file (disk files only). |
| REWIND_ON_CLOSE | BIT(1) | REWIND_ON_CLOSE option is enabled or disabled. |
| REWIND_ON_OPEN | BIT(1) | REWIND_ON_OPEN option is enabled or disabled. |
| SCALARVARYING | BIT(1) | SCALARVARYING option is enabled or disabled. |
| SHARED_READ | BIT(1) | SHARED_READ option is enabled or disabled. |
| SHARED_WRITE | BIT(1) | SHARED_WRITE option is enabled or disabled. |
| SPOOL | BIT(1) | SPOOL option is enabled or disabled. |
| SUPERSEDE | BIT(1) | SUPERSEDE option is enabled or disabled. |
| SYSTEM_PROTECTION | CHAR(4) VARYING | Protection for system users. |
| TEMPORARY | BIT(1) | TEMPORARY option is enabled or disabled. |
| TRUNCATE | BIT(1) | TRUNCATE option is enabled or disabled. |
| WORLD_PROTECTION | CHAR(4) VARYING | Protection for world users. |
| WRITE_BEHIND | BIT(1) | WRITE_BEHIND option is enabled or disabled. |
| WRITE_CHECK | BIT(1) | WRITE_CHECK option is enabled or disabled. |
Table 9.3, “File Attribute Information Returned by DISPLAY” summarizes the file attribute information returned by DISPLAY. All names in the table are level-2 members of the structure PLI_FILE_DISPLAY.
|
Member Name |
Type of Value Returned |
Data Type of Meaning |
|---|---|---|
| COLUMN_NUMBER | FIXED BIN | Current column (stream output files only). |
| DIRECT | BIT(1) | File has or does not have DIRECT attribute. |
| EXPANDED_TITLE | CHAR(128) VARYING | Expanded file specification. |
| FILE_ORGANIZATION | CHAR(3) | SEQ, REL, or IDX. |
| FORTRAN_FORMAT | BIT(1) | File has or does not have FTN (ASA) carriage control. |
| INPUT | BIT(1) | File has or does not have INPUT attribute. |
| KEYED | BIT(1) | File has or does not have KEYED attribute. |
| LINE_NUMBER | FIXED BIN | Current line number (stream output files only). |
| LINESIZE | FIXED BIN | File's line size (stream output files only). |
| NUMBER_OF_KEYS | FIXED BIN | Number of keys (indexed sequential files only). |
| OUTPUT | BIT(1) | File has or does not have OUTPUT attribute. |
| PAGE_NUMBER | FIXED BIN | Current page number (PRINT files only). |
| PAGESIZE | FIXED BIN | Page size (PRINT files only). |
| BIT(1) | File has or does not have PRINT attribute. | |
| RECORD | BIT(1) | File has or does not have RECORD attribute. |
| SEQUENTIAL | BIT(1) | File has or does not have SEQUENTIAL attribute. |
| STREAM | BIT(1) | File has or does not have STREAM attribute. |
| UPDATE | BIT(1) | File has or does not have UPDATE attribute. |
Table 9.4, “Device Information Returned by DISPLAY” lists the names of the structure members that contain information about the device to which a file is written or from which the file is to be read. All of the names in Table 9.4, “Device Information Returned by DISPLAY” are level-3 members of the structure PLI_FILE_DISPLAY; they each appear within the following minor structures, which have identical declarations:
DEVICE
SPOOLING_DEVICE
If the field PLI_FILE_DISPLAY.DEVICE.SPL is true, then the members of the minor structure DEVICE contain information about the device that is spooled. Members of minor structure PLI_FILE_DISPLAY.SPOOLING_DEVICE contain information about the intermediate, or spooling, device.
All fields within these structures are BIT(1) values.
9.2. EXTEND Built-In Subroutine
The EXTEND built-in subroutine increases the amount of space allocated to a disk file. Its calling sequence is as follows:
CALL EXTEND (file-reference,integer-expression);
file-referenceSpecifies the name of a file variable or constant associated with the file that is to be extended. If the file is not currently opened, the EXTEND subroutine opens the file with the OUTPUT attribute in order to extend it.
integer-expressionIs a fixed binary expression in the range 0 to 4,294,967,295, specifying the number of 512-byte disk blocks to be added to the file. If 0 is specified, PL/I uses the default extension quantity for the file.
To specify a value larger than 2,147,483,647 (the largest value that can be contained in a fixed binary integer in PL/I), you must express the number as a negative value; RMS interprets the number as an unsigned integer.
Use the EXTEND built-in subroutine to explicitly extend a file during processing. Normally, RMS extends a file automatically, using a current extension size value, whenever an output operation causes a file to exceed its allocated space. The default value that RMS uses to extend a file is set by the ENVIRONMENT option EXTENSION_SIZE.
You can improve the performance of a program that is going to add a large number of records to a file by making an explicit call to EXTEND before adding records to the file. If the call to EXTEND occurs before records are added, then RMS does not need to extend the file during the actual I/O operations.
9.3. FLUSH Built-In Subroutine
The FLUSH built-in subroutine writes all RMS buffers that have been modified and preserves all of the file attributes of the file. This subroutine provides the ability to checkpoint a file during its processing and ensure its integrity. Its calling sequence is as follows:
CALL FLUSH (file-reference);file-referenceSpecifies the name of the file variable or file constant associated with the file whose buffers are to be flushed. If the file is not currently opened, the FLUSH subroutine performs no operation.
Use the FLUSH subroutine to explicitly request RMS to write all internal file buffers back to the file. This subroutine is called implicitly by the REWIND and NEXT_VOLUME built-in subroutines.
9.4. FREE Built-In Subroutine
The FREE built-in subroutine unlocks all the locked records in a specified file. Its calling sequence is as follows:
CALL FREE (file-reference);file-referenceSpecifies the name of the file variable or file constant associated with the file whose records are to be unlocked.
9.5. NEXT_VOLUME Built-In Subroutine
The NEXT_VOLUME built-in subroutine performs the positioning and labeling functions necessary when the next volume is required during I/O to a magnetic tape file that spans more than one physical tape volume. Its calling sequence is as follows:
CALL NEXT_VOLUME (file-reference);file-referenceSpecifies the name of the file constant or file variable associated with the tape volume set that is being processed. If the file is not currently open, the NEXT_VOLUME subroutine implicitly opens the file with the attributes specified in the declaration of the file.
When a multivolume tape file is being read or written, volume switching is normally transparent to the PL/I program. RMS and the magnetic tape Ancillary Control Program (ACP) perform all the steps necessary to ensure that the next required volume is physically mounted, initialized, and verified.
However, when a program must advance to the next volume before reaching the end of the current volume on input, or before the end of the tape is reached on output, it can call the NEXT_VOLUME built-in subroutine. This subroutine performs all the necessary volume checking when a multivolume tape file is being read. When a file is being written, the subroutine writes the appropriate information on the output tapes.
For more detailed explanations of volume switching, see the OpenVMS Record Management Services Reference Manual and the OpenVMS DCL Dictionary.
9.6. RELEASE Built-In Subroutine
The RELEASE built-in subroutine unlocks a specified record in a file. Its calling sequence is as follows:
CALL RELEASE (file-reference,variable-reference);
file-referenceSpecifies the name of the file variable or file constant associated with the file on which the operation is to be performed. This file must have been opened with the RECORD_ID_ACCESS option of the ENVIRONMENT attribute.
variable-referenceSpecifies the record identification of the record to be unlocked. It must be declared (2) FIXED BINARY, and it must be connected.
9.7. REWIND Built-In Subroutine
The REWIND built-in subroutine positions a file so that the next record to be read will be the first record in the file or index. Its calling sequence is as follows:
CALL REWIND (file-reference);file-referenceSpecifies the name of the file constant or file variable associated with the file to be rewound. If the file is not currently open, the REWIND subroutine implicitly opens the file with the attributes specified in the declaration of the file.
Use this subroutine to begin processing a file at its logical beginning. This subroutine is valid for disk files of all organizations and for sequential files on tape volumes. The position of the file following the call to the REWIND subroutine is as follows:
A sequential file is positioned at its first record.
A relative record is positioned at the first occupied cell.
An indexed sequential file is positioned at the lowest key value in the current index.
A tape file on a single volume is rewound; a tape file on a multivolume tape set is rewound to the beginning of the volume set.
You can also use the REWIND built-in subroutine to reposition a stream file after an end-of-file condition. Normally, if end-of-file (Ctrl/z on a terminal) is entered during an input operation on a stream input file, the PL/I program must close the input file and reopen it before any more data can be read. However, an ENDFILE ON-unit can be written as follows:
ON ENDFILE(STREAMFIL) CALL REWIND(STREAMFIL);
This ON-unit calls the REWIND built-in subroutine each time an end-of-file condition is encountered for the file constant STREAMFIL. The REWIND built-in subroutine repositions the stream file at its beginning so that the program can continue reading input.
9.8. SPACEBLOCK Built-In Subroutine
The SPACEBLOCK built-in subroutine positions a file forward or backward a specified number of blocks. This subroutine can be used to process unlabeled magnetic tapes, as well as sequential disk files that are being processed with block I/O. Its calling sequence is as follows:
CALL SPACEBLOCK (file-reference,integer-expression);
file-referenceSpecifies the name of the file constant or file variable that is to be spaced. If the file is open, it must have been opened with the BLOCK_IO option. If the file is not open, the SPACEBLOCK subroutine opens the file with the BLOCK_IO option.
integer-expressionIs a fixed binary expression specifying the number of blocks to be spaced forward or backward. If the expression is negative, the file is spaced backward the specified number of blocks. If the expression is positive, the tape is spaced forward the specified number of blocks.