DocumentationEndless PL/I for OpenVMSUser Manual  ·  ESS-PFVUM-001

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.

Table 9.1. Summary of File-Handling Built-In Subroutines
SubroutineFunction
DISPLAYReturns information about a file.
EXTENDAllocates additional disk blocks for a file.
FLUSHRequests the file system to write all buffers onto disk to preserve the current status of a file.
FREEUnlocks all the locked records in a file.
NEXT_VOLUMEBegins processing the next volume in a multivolume tape set.
RELEASEUnlocks a specified record in a file.
REWINDPositions a file at its beginning or at a specific record.
SPACEBLOCKPositions 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-reference

Specifies 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-reference

Specifies 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:

  • Members containing information about the settings of ENVIRONMENT options

  • Members containing information on file attributes

  • Members containing information on device attributes

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.

Table 9.2. ENVIRONMENT Option Values Returned by DISPLAY

Member Name

Data Type of

Value Returned

Meaning

APPENDBIT(1)APPEND option is enabled or disabled.
BACKUP_DATEBIT(64) ALIGNEDBackup date of file (disk files only).
BATCHBIT(1)BATCH option is enabled or disabled.
BLOCK_BOUNDARY_FORMATBIT(1)Records cannot cross block boundaries.
BLOCK_IOBIT(1)File is opened for block I/O.
BLOCK_SIZEFIXED BINBlock size of file (magnetic tape files only).
BUCKET_SIZEFIXED BINBucket size of file (disk files only).
CARRIAGE_RETURN_FORMATBIT(1)Records have carriage return carriage control.
CONTIGUOUSBIT(1)CONTIGUOUS option is enabled or disabled.
CONTIGUOUS_BEST_TRYBIT(1)CONTIGUOUS_BEST_TRY option is enabled or disabled.
CREATION_DATEBIT(64) ALIGNEDCreation date of file.
CURRENT_POSITIONBIT(1)CURRENT_POSITION option is enabled or disabled.
DEFERRED_WRITEBIT(1)DEFERRED_WRITE option is enabled or disabled.
DELETEBIT(1)DELETE option is enabled or disabled.
EXPIRATION_DATEBIT(64) ALIGNEDExpiration date of file.
EXTENSION_SIZEFIXED BINCurrent extension size (disk files only).
FILE_ID(6) FIXED BINFile identification (disk files only).
FILE_SIZEFIXED BINFile allocation (disk files only).
FIXED_CONTROL_SIZEFIXED BINSize of fixed-control area.
FIXED_LENGTH_RECORDSBIT(1)File has fixed-length records.
GROUP_PROTECTIONCHAR(4) VARYINGProtection for group members.
IGNORE_LINE_MARKSBIT(1)IGNORE_LINE_MARKS option is enabled or disabled.
INDEX_NUMBERFIXED BINCurrent index number.
INDEXEDBIT(1)File is or is not an indexed sequential file.
INITIAL_FILLBIT(1)INITIAL_FILL option is enabled or disabled.
MAXIMUM_RECORD_NUMBERFIXED BINRelative file maximum relative record.
MAXIMUM_RECORD_SIZEFIXED BINLargest record size.
MULTIBLOCK_COUNTFIXED BINMultiblock count (disk files only).
MULTIBUFFER_COUNTFIXED BINMultibuffer count.
NO_SHAREBIT(1)NO_SHARE option is enabled or disabled.
OWNER_GROUPFIXED BINGroup number of file's owner.
OWNER_MEMBERFIXED BINMember number of file's owner.
OWNER_PROTECTIONCHAR(4) VARYINGProtection for file's owner.
RETRIEVAL_POINTERSFIXED BINNumber of mapping pointers.
PRINTER_FORMATBIT(1)Records have printer carriage control.
READ_AHEADBIT(1)READ_AHEAD option is enabled or disabled.
READ_CHECKBIT(1)READ_CHECK option is enabled or disabled.
RECORD_ID_ACCESSBIT(1)File is opened for access by record identification.
REVISION_DATEBIT(64) ALIGNEDRevision date of file (disk files only).
REWIND_ON_CLOSEBIT(1)REWIND_ON_CLOSE option is enabled or disabled.
REWIND_ON_OPENBIT(1)REWIND_ON_OPEN option is enabled or disabled.
SCALARVARYINGBIT(1)SCALARVARYING option is enabled or disabled.
SHARED_READBIT(1)SHARED_READ option is enabled or disabled.
SHARED_WRITEBIT(1)SHARED_WRITE option is enabled or disabled.
SPOOLBIT(1)SPOOL option is enabled or disabled.
SUPERSEDEBIT(1)SUPERSEDE option is enabled or disabled.
SYSTEM_PROTECTIONCHAR(4) VARYINGProtection for system users.
TEMPORARYBIT(1)TEMPORARY option is enabled or disabled.
TRUNCATEBIT(1)TRUNCATE option is enabled or disabled.
WORLD_PROTECTIONCHAR(4) VARYINGProtection for world users.
WRITE_BEHINDBIT(1)WRITE_BEHIND option is enabled or disabled.
WRITE_CHECKBIT(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.

Table 9.3. File Attribute Information Returned by DISPLAY

Member Name

Type of

Value Returned

Data Type

of Meaning

COLUMN_NUMBERFIXED BINCurrent column (stream output files only).
DIRECTBIT(1)File has or does not have DIRECT attribute.
EXPANDED_TITLECHAR(128) VARYINGExpanded file specification.
FILE_ORGANIZATIONCHAR(3)SEQ, REL, or IDX.
FORTRAN_FORMATBIT(1)File has or does not have FTN (ASA) carriage control.
INPUTBIT(1)File has or does not have INPUT attribute.
KEYEDBIT(1)File has or does not have KEYED attribute.
LINE_NUMBERFIXED BINCurrent line number (stream output files only).
LINESIZEFIXED BINFile's line size (stream output files only).
NUMBER_OF_KEYSFIXED BINNumber of keys (indexed sequential files only).
OUTPUTBIT(1)File has or does not have OUTPUT attribute.
PAGE_NUMBERFIXED BINCurrent page number (PRINT files only).
PAGESIZEFIXED BINPage size (PRINT files only).
PRINTBIT(1)File has or does not have PRINT attribute.
RECORDBIT(1)File has or does not have RECORD attribute.
SEQUENTIALBIT(1)File has or does not have SEQUENTIAL attribute.
STREAMBIT(1)File has or does not have STREAM attribute.
UPDATEBIT(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.

Table 9.4. Device Information Returned by DISPLAY
Member NameMeaning
ALLDevice is or is not allocated.
AVLDevice is or is not online and available.
CCLDevice has or does not have carriage control.
DIRDevice is or is not directory structured.
DMTDevice is or is not marked for dismounting.
ELGDevice is or is not enabled for error logging.
FODDevice is or is not file-oriented.
FORDevice is or is not a foreign device.
GENDevice is or is not a generic device.
IDVDevice is or is not capable of input.
MBXDevice is or is not a mailbox.
MNTDevice is or is not mounted.
NETDevice is or is not a network device.
ODVDevice is or is not capable of output.
RCKDevice performs read checking.
RECDevice is or is not a record-oriented device (terminal or line printer, for example).
RNDDevice is or is not random access in nature.
RTMDevice is or is not a real-time device.
SDIDevice has a master directory only.
SHRDevice is or is not shareable.
SPLDevice is or is not spooled.
SQDDevice is or is not sequential block-oriented (magnetic tape).
SWLDevice is or is not currently software write-locked.
TRMDevice is or is not a terminal.
WCKDevice performs write checking.

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-reference

Specifies 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-expression

Is 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-reference

Specifies 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-reference

Specifies 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-reference

Specifies 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-reference

Specifies 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-reference

Specifies 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-reference

Specifies 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-reference

Specifies 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-expression

Is 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.