Chapter 7
Options of the ENVIRONMENT Attribute
The options of the ENVIRONMENT attribute provided by PL/I allow you to:
Describe the attributes of a file when it is created.
Request special processing and optimization options when the file is being read or written.
Specify the disposition of a file when it is closed.
Most of the options of the ENVIRONMENT attribute correspond directly to OpenVMS Record Management Services (RMS) options and control values. PL/I, in some cases, provides different defaults than RMS.
7.1. Specifying and Using ENVIRONMENT Options
All ENVIRONMENT options can be specified in the declaration of a file constant or in an OPEN statement. Certain options can also be specified in a CLOSE statement.
Note
If you declare a file constant or file variable explicitly or implicitly as EXTERNAL, you must use identical attributes, including ENVIRONMENT options, in all blocks that declare the file.
7.1.1. Arguments for ENVIRONMENT Options
ENVIRONMENT options fall into the following categories, based on whether they require an argument and the type of argument required:
Options that require you to specify an expression representing a value to override a default value provided by PL/I
Options that require you to provide a reference to a variable that either contains information pertinent to opening the related file or that will receive information when the related file is opened
Options that can be specified with a Boolean expression that enables or disables the option (if no value is specified with an option, the option is enabled)
All arguments must be specified in parentheses following the name of the ENVIRONMENT option. For example:
ENVIRONMENT (MAXIMUM_RECORD_SIZE(1024), FILE_ID_TO(WORKFILE_ID), FIXED_LENGTH_RECORDS('1'B) )
Considerations for specifying each type of argument are given in the following sections.
7.1.1.1. Expressions
You can use integer expressions and character expressions in expression arguments for ENVIRONMENT options. The ways you can specify these arguments differ for DECLARE statements and for OPEN and CLOSE statements.
In a DECLARE statement, you must specify a constant expression. Integer expressions can consist of integer constants, constant identifiers defined by %REPLACE statements, and the operators +, -, *, and /. You must specify character expressions using character-string constants.
In an OPEN or a CLOSE statement, you can specify the argument using constant expressions or variable references, or expressions or variable references of the required type.
If a single variable is specified for an expression, its data type must be convertible to the data type of the option. All integer constants and expressions are converted to FIXED BINARY.
You can specify all character-string expressions using varying or nonvarying strings. The description of the option specifies the maximum length of a string argument.
For any of these options, PL/I applies a default value if no option is specified for the file when it is opened.
7.1.1.2. Variable References
Options that are specified by variable references cannot be specified in a DECLARE statement. The data type of the variable must match the data type described in the option description.
7.1.1.3. Boolean Values
For an option that can be enabled or disabled, you can specify a Boolean constant, that is, '1'B (to enable) or '0'B (to disable) the option in a DECLARE statement. In an OPEN or CLOSE statement, you can specify a Boolean constant, variable, or expression.
An option that is specified without a value is interpreted as enabled. For example, the following are equivalent:
ENVIRONMENT(FIXED_LENGTH_RECORDS) ENVIRONMENT(FIXED_LENGTH_RECORDS('1'B))
For arguments of this type, PL/I converts any non-Boolean value to BIT(1) ALIGNED.
7.1.2. Interpretation of ENVIRONMENT Options for Existing Files
Many ENVIRONMENT options specify values that can be set only when a file is created. For example, the length of records in a file with fixed-length records is set when the file is created and cannot be changed thereafter. When these options are specified for a file, they apply to the file only if the opening of the file actually results in the creation of a new file. If the file opening causes an existing file to be opened, the option is ignored.
7.1.3. Determining ENVIRONMENT Options
A PL/I program can determine the value or setting of an ENVIRONMENT option at run time for an indicated file by calling the DISPLAY built-in subroutine. This built-in subroutine returns information about a specified PL/I file to a user-specified structure. The member names in the structure correspond to the keywords of the ENVIRONMENT attribute.
For a description of the values returned by this subroutine and for an example of calling it, see Chapter 9, File-Handling Built-In Subroutines.
Certain ENVIRONMENT options themselves return information to the program when an existing file is opened. For example, you can specify the FIXED_CONTROL_SIZE_TO option when an existing file with a fixed control area is opened. PL/I returns the size of the fixed control area to the program.
7.1.4. Device Independence of ENVIRONMENT Options
Many ENVIRONMENT options apply only to a particular type of device or to a specific file organization. For example, the REWIND_ON_CLOSE and REWIND_ON_OPEN options apply only to magnetic tape files, and the FILE_SIZE option applies only to disk files.
When any ENVIRONMENT option is specified for a device to which the option does not apply, the option is ignored.
7.1.5. Conflicting and Invalid ENVIRONMENT Options
Conflicting or invalid options or values for options can be detected during compilation or at run time. At compile time, the compiler issues a diagnostic message to indicate the error.
At run time, the UNDEFINEDFILE condition is signaled if conflicting options are in effect or if conflicting values are specified for the same option. For example, if the FILE_SIZE option is specified in the DECLARE and OPEN statements for a given file and if the options specify different values, UNDEFINEDFILE is signaled.
For run-time errors, an ON-unit can reference the ONCODE built-in function to determine the specific error, if desired. If no ON-unit exists for the UNDEFINEDFILE condition, the PL/I run-time system displays an error message describing the error that occurred.
7.2. Summary of ENVIRONMENT Options
The options to the PL/I ENVIRONMENT attribute are summarized in alphabetical order in Table 7.1, “Summary of ENVIRONMENT Options”. Columns in Table 7.1, “Summary of ENVIRONMENT Options” provide the following information:
| Option and Usage | Gives the name of the ENVIRONMENT option, its argument (if any), and a brief description of its usage. An option that does not show an argument can be specified with a Boolean argument. |
| Specify At |
Indicates when the option is meaningful. The possible items in this column are as follows: Create-the option can be specified on a DECLARE or OPEN. It is meaningful only when a file is created. Open-the option can be specified on a DECLARE or OPEN. It is meaningful when an existing file is opened. Close-the option can be specified on a DECLARE, OPEN, or CLOSE. It takes effect when the file is closed. Update-the option is meaningful when an existing file is opened with the UPDATE attribute or with the ENVIRONMENT option APPEND. |
| Valid I/O Types | Indicates whether the option is valid for stream or record files. |
| Default Value | Indicates the default value, if any, when the option is not specified for a file. |
| Data Type | Specifies the required data type of the argument. |
Appendix B, Correspondence of PL/I and RMS lists the options and their corresponding RMS equivalents.
| Option and Usage | Specify At | Valid I/O Types | Default Value | Data Type |
|---|---|---|---|---|
|
APPEND Places output for a file at the end of a file. |
Create Open |
Record Stream | Disabled | BIT(1) |
|
BACKUP_DATE (variable) Overrides the default backup date of the file. |
Create Open |
Record Stream | Date and time file was last backed up | BIT(64) ALIGNED |
|
BATCH Submits a copy of the file to the system batch job queue on close. |
Create Open Close |
Record Stream | Disabled | BIT(1) |
|
BLOCK_BOUNDARY_FORMAT Indicates that records must not cross block boundaries. | Create |
Record Stream | Disabled | BIT(1) |
|
BLOCK_IO Specifies a file will be read or written by block instead of records. |
Create Open | Record | Disabled | BIT(1) |
|
BLOCK_SIZE (expression) Specifies the size of a block for the creation of a magnetic tape file. | Create |
Record Stream | Mount BLOCKSIZE Value | FIXED BINARY |
|
BUCKET_SIZE (expression) Defines the number of 512-byte blocks in a bucket for an indexed sequential or a relative file. | Create | Record | Maximum record size | FIXED BINARY |
|
CARRIAGE_RETURN_FORMAT Indicates that records in the file will be printed with default carriage control. | Create | Record | Enabled | BIT(1) |
|
CONTIGUOUS Specifies that an output file must be placed in a physically contiguous extent on disk. | Create |
Record Stream | Disabled | BIT(1) |
|
CONTIGUOUS_BEST_TRY Requests that if possible an output file be placed in a physically contiguous extent on disk. | Create |
Record Stream | Disabled | BIT(1) |
|
CREATION_DATE (variable) Overrides default creation date of the file. | Create |
Record Stream | Current date and time | BIT(64) ALIGNED |
|
CURRENT_POSITION Leaves magnetic tape positioned at last close. |
Create Open |
Record Stream | Disabled | BIT(1) |
|
DEFAULT_FILE_NAME (expression) Defines a default file specification for a file. |
Create Open |
Record Stream | '.DAT' | CHAR(128) |
|
DEFERRED_WRITE Requests file system optimization of output. |
Create Open | Record | Disabled | BIT(1) |
|
DELETE Specifies that the file be deleted when it is closed. |
Create Open Close |
Record Stream | Disabled | BIT(1) |
|
EXPIRATION_DATE (variable) Defines the expiration date for a magnetic tape file. | Create |
Record Stream | Creation date | BIT(64) ALIGNED |
|
EXTENSION_SIZE (expression) Specifies a default extension size for a disk file. |
Create Open |
Record Stream | System default | FIXED BINARY |
|
FILE_ID (variable) Identifies a file by its internal file identification. | Open |
Record Stream | Not applicable | (6)FIXED BINARY |
|
FILE_ID_TO (variable) Identifies a file by its internal file identification. |
Create Open |
Record Stream | Not applicable | (6)FIXED BINARY |
|
FILE_SIZE (expression) Defines the initial number of blocks to be allocated for a file. | Create |
Record Stream | Not applicable | FIXED BINARY |
|
FIXED_CONTROL_SIZE (expression) Defines records as variable length with fixed-length control, and specifies the size of the fixed control area. | Create | Record | Disabled | FIXED BINARY |
|
FIXED_CONTROL_SIZE_TO (variable) Defines records as variable length with fixed-length control and specifies the size of the fixed control area. On open, returns the length of the fixed control area. |
Create Open | Record | Disabled | FIXED BINARY |
|
FIXED_LENGTH_RECORDS Specifies a file with fixed-length records of a maximum record size. | Create | Record | Disabled | BIT(1) |
|
GROUP_PROTECTION (expression) Defines the type of file access allowed to members of the owner's group. | Create |
Record Stream | Current process default | CHAR(4) |
|
IGNORE_LINE_MARKS Specifies that end-of-line characters are not to be treated as field delimiters in GET LIST statements. |
Create Open | Stream | Disabled | BIT(1) |
|
INDEX_NUMBER (expression) Specifies the initial index to use in accessing records in an indexed sequential file. |
Create Open | Record | 0 | FIXED BINARY |
|
INDEXED Defines an indexed sequential file. |
Create Open | Record | Disabled | BIT(1) |
|
INITIAL_FILL Requests the file system to leave unused space in file index overflow buckets. | Open | Record | Disabled | BIT(1) |
|
MAXIMUM_RECORD_NUMBER (expression) Specifies the largest record number that will be valid for records in a relative file. | Create | Record | 0 | FIXED BINARY |
|
MAXIMUM_RECORD_SIZE (expression) Specifies the maximum size that is valid for any record in the file. | Create | Record | 512 bytes[a] | FIXED BINARY |
|
MULTIBLOCK_COUNT (expression) Specifies the number of blocks to be allocated for file system buffering. |
Create Open | Record | Current process default | FIXED BINARY |
|
MULTIBUFFER_COUNT (expression) Specifies the number of buffers to be allocated for file system buffering. |
Create Open | Record | Current process default | FIXED BINARY |
|
NO_SHARE Prohibits all types of shared access to the file. |
Create Open | Record | Enabled[b] | BIT(1) |
|
OWNER_GROUP (expression) Specifies the group number in the user identification code (UIC) of the owner of the file. | Create |
Record Stream | Current process group number | FIXED BINARY |
|
OWNER_ID (expression) Specifies the entire 32-bit identifier of the owner of the file; can be used instead of OWNER_GROUP and OWNER_MEMBER. | Create |
Record Stream | Current process identifier (UIC) | FIXED BINARY |
|
OWNER_MEMBER (expression) Specifies the member number in the user identification code (UIC) of the owner of the file. | Create |
Record Stream | Current process member number | FIXED BINARY |
|
OWNER_PROTECTION (expression) Specifies the type of file access allowed the owner of the file. | Create |
Record Stream | Current process default | CHAR(4) |
|
PRINTER_FORMAT Specifies that records in the file will be printed with printer format carriage control embedded in the fixed control area of the records. | Create | Record | Disabled | BIT(1) |
|
READ_AHEAD Requests file system optimization on read operations. | Open |
Record Stream | Disabled | BIT(1) |
|
READ_CHECK Requests verification of read operations. |
Create Open |
Record Stream | Disabled | BIT(1) |
|
RECORD_ID_ACCESS Indicates that records will be accessed by internal file system identification. |
Create Open | Record | Disabled | BIT(1) |
|
RETRIEVAL_POINTERS (expression) Specifies the number of file system extent pointers to be maintained for file access. |
Create Open |
Record Stream | Current system default | FIXED BINARY |
|
REVISION_DATE (variable) Overrides the default revision date of the file. | Close |
Record Stream | Date and time file is closed | BIT(64) ALIGNED |
|
REWIND_ON_CLOSE Requests that a magnetic tape volume be rewound when the file is closed. |
Create Open Close |
Record Stream | Disabled | BIT(1) |
|
REWIND_ON_OPEN Requests that a magnetic tape volume be rewound when the file is opened. |
Create Open |
Record Stream | Enabled | BIT(1) |
|
SCALARVARYING Specifies that varying character strings will be read/written using the entire storage of the variable. |
Create Open | Record | Disabled | BIT(1) |
|
SHARED_READ Allows other users to read records in the file. |
Create Open | Record | Enabled[c] | BIT(1) |
|
SHARED_WRITE Allows other users to read and write records in the file. |
Create Open | Record | Disabled | BIT(1) |
|
SPOOL Queues a copy of the file to the system printer when the file is closed. |
Create Open Close |
Record Stream | Disabled | BIT(1) |
|
SUPERSEDE Replaces an existing file with the same file name, file type, and version number. | Create |
Record Stream | Disabled | BIT(1) |
|
SYSTEM_PROTECTION (expression) Defines the type of file access allowed to users with system user identification codes (UICs). | Create |
Record Stream | Current process default | CHAR(4) |
|
TEMPORARY Specifies a temporary file for which no directory entry is made. | Create |
Record Stream | Disabled | BIT(1) |
|
TRUNCATE Truncates a sequential file at its logical end-of-file when the file is closed. |
Create Update Close |
Record Stream | Disabled | BIT(1) |
|
USER_OPEN ( Specifies a user-written function to open the file. |
Create Open |
Record Stream | RMS Open | ENTRY |
|
WORLD_PROTECTION (expression) Specifies the type of file access allowed to general system users. | Create |
Record Stream | Current process default | CHAR(4) |
|
WRITE_BEHIND Requests file system optimization on output operations. |
Create Update |
Record Stream | Disabled | BIT(1) |
|
WRITE_CHECK Requests verification of output operations. |
Create Update |
Record Stream | Disabled | BIT(1) |
[a] For sequential files with fixed-length records. For sequential files with variable-length records, the default is 510 bytes. For relative files, the default is 480 bytes. [b] Disabled if the file is opened for input, enabled if opened for output or update. [c] Enabled if the file is opened for input, otherwise disabled. | ||||
The following sections describe each option in detail.
7.2.1. APPEND Option
The APPEND option opens an existing file for output so that new records are added following the current end-of-file. The format of this option is as follows:
APPEND [ (boolean-expression) ]Rules
The APPEND option is meaningful only when an existing file is opened with the OUTPUT attribute. It overrides the default action for opening an output file, which is to create a new file with a higher version number.
If the APPEND option is specified when a file is created, the option is ignored; that is, if the file does not exist, a new file is created.
APPEND conflicts with the SUPERSEDE option; it is invalid for a file opened with the INPUT or UPDATE attribute.
Usage
Use the APPEND option to open a file and position it at the end-of-file. For example, to add records at the end of a file on a magnetic tape, you can open the file as follows:
DECLARE TAPEFILE FILE SEQUENTIAL OUTPUT; ⋮ OPEN FILE(TAPEFILE) ENVIRONMENT(APPEND);
This OPEN statement opens the file TAPEFILE. The file constant TAPEFILE is assumed to be a logical name. The system translates the logical name to locate the tape device with which it is associated. The tape is positioned at its current end-of-file.
APPEND can also be used for sequential disk files and for mailboxes.
7.2.2. BACKUP_DATE Option
The BACKUP_DATE option lets you specify a date and time field for the file's backup date, allowing you to override the existing backup date and time. The format of this option is as follows:
BACKUP_DATE (variable-reference)variable-referenceSpecifies the name of a BIT(64) ALIGNED variable containing an absolute time value in system format. The value specifies the date and time to be used as the file's backup date and time.
Rules
The BACKUP_DATE option is meaningful only when the file is opened or created.
Usage
You can obtain the time value required by using the Convert ASCII String to Binary Time system service (SYS$BINTIM). For an example of a call to this procedure to obtain a system time value, see Chapter 11, Using PL/I in the Common Language Environment.
7.2.3. BATCH Option
The BATCH option requests that the file be submitted to the system batch job queue when it is closed. The format of this option is as follows:
BATCH [ (boolean-expression) ]Rules
The BATCH option can be specified when a file is created, opened, or closed.
This option applies only to stream files or to sequential record files.
Once the BATCH option has been specified for a file on a particular file opening, it cannot be disabled.
BATCH conflicts with the INDEXED option and with the KEYED and DIRECT file description attributes.
Usage
When you specify both the TEMPORARY and DELETE options in conjunction with the BATCH option, the file is submitted to the batch job queue and is marked for deletion after the batch job is completed.
7.2.4. BLOCK_BOUNDARY_FORMAT Option
The BLOCK_BOUNDARY_FORMAT option indicates that records in the file must not cross block boundaries. The format of this option is as follows:
BLOCK_BOUNDARY_FORMAT [ (boolean-expression) ]Rules
The BLOCK_BOUNDARY_FORMAT option is meaningful only when a file is created.
This option applies only to sequential files; it is ignored if specified for relative or indexed sequential files.
If the BLOCK_BOUNDARY_FORMAT option is specified for a file, the maximum record size must be less than 512 bytes.
BLOCK_BOUNDARY_FORMAT conflicts with the BLOCK_IO option. However, a file that is created with the BLOCK_BOUNDARY_FORMAT option can later be read with the BLOCK_IO option.
Usage
The BLOCK_BOUNDARY_FORMAT option can be paired with the CARRIAGE_RETURN_FORMAT or PRINTER_FORMAT option to define the attributes of a file's records.
This option can be useful for the creation of files that will be read in terms of blocks. Note, however, that this option can result in unused disk space when records do not fill blocks.
7.2.5. BLOCK_IO Option
The BLOCK_IO option indicates that all I/O operations on the file will be in terms of physical blocks rather than records. In an I/O statement, a block is treated as if it were a single logical record. The format of this option is as follows:
BLOCK_IO [ (boolean-expression) ]Rules
The BLOCK_IO option is meaningful when a file is created or opened. The file can be opened with any of the attributes INPUT, OUTPUT, or UPDATE. If the file is opened for output, the created file is always sequential.
This option applies only to disk files and to magnetic tape files.
The BLOCK_IO option conflicts with the STREAM file description attribute and with the following ENVIRONMENT options:
BLOCK_BOUNDARY_FORMAT
CARRIAGE_RETURN_FORMAT
FIXED_CONTROL_SIZE
FIXED_LENGTH_RECORDS
PRINTER_FORMAT
RECORD_ID_ACCESS
Usage
Disk Files: When a disk file is opened for block I/O, each READ or WRITE statement always transfers data beginning on a block boundary; multiple physical blocks can be read or written. The number of bytes transferred in an I/O operation depends on the size of the input or output variable specified in the READ or WRITE statement. When a READ statement reads fewer bytes than specified by the size of the input variable, the ERROR condition is signaled; this condition is equivalent to an end-of-file indication.
When a disk file is opened with the BLOCK_IO option and with the KEYED and UPDATE attributes, the file can be accessed with keyed READ, REWRITE, and WRITE statements. In this case, the key value is the virtual block number of a block. The first block is always numbered 1. There is no distinction between the statements REWRITE KEY(n) and WRITE KEYFROM(n); both statements store data in the block numbered n of the file. If the file is a sequential file, it is extended if necessary.
Magnetic Tape Files: In a magnetic tape file, the size of the block is the size specified when the tape was created; if the tape was not previously written, the block size is set when the tape is mounted. Sequential READ and WRITE statements transfer a block at a time.
7.2.6. BLOCK_SIZE Option
The BLOCK_SIZE option specifies the size, in bytes, of the blocks when a magnetic tape file is created. Its format is as follows:
BLOCK_SIZE(integer-expression)integer-expressionSpecifies a numeric value in the range 20 through 65,532, giving the number of bytes in a block for the tape file. If the BLOCK_SIZE option is not specified, or if the expression is specified as 0, the block size specified when the tape volume was mounted is used by default.
Rules
The BLOCK_SIZE option is meaningful only when a file is created.
This option applies only to magnetic tape files.
Usage
When a tape file is opened with the BLOCK_IO option of ENVIRONMENT, the block size of the file is used to determine the number of bytes to be transferred in a single I/O operation.
7.2.7. BUCKET_SIZE Option
The BUCKET_SIZE option lets you specify the number of blocks to be used for each bucket when you create a relative file. The BUCKET_SIZE option has the following format:
BUCKET_SIZE(integer-expression)integer-expressionIs a fixed binary value in the range 0 through 32, representing the number of blocks in each bucket. If the bucket size is specified as 0, or if it is not specified, PL/I applies the current RMS default. This default can be set with the DCL command SET RMS_DEFAULT; its current value can be determined with the command SHOW RMS_DEFAULT.
Rules
The BUCKET_SIZE option is meaningful only when a file is created.
This option applies only to relative files.
Usage
Selection of a bucket size for a relative file depends on the size of the records in the file. Although records within a bucket can cross block boundaries, records cannot cross bucket boundaries. Therefore, the number of blocks per bucket that you specify with this option must conform to one of the following formulas.
Relative Files with Fixed-Length Records
display bsiz = ((rlen + 1)*rnum)/512
bsizIs the number of blocks per bucket, rounded up to the next higher integer. The result must be in the range 1 through 32.
rlenIs the size of the fixed-length records (specified by the MAXIMUM_RECORD_SIZE option).
rnumIs the number of records that you want in each bucket.
The overhead required for these files consists of one byte for each record.
Relative Files with Variable-Length Records
display bsiz = ((rmax + 3)*rnum)/512
bsizIs the number of blocks per bucket, rounded up to the next higher integer. The result must be in the range 1 through 32.
rmaxIs the maximum size of any record in the file (specified by the MAXIMUM_RECORD_SIZE option).
rnumIs the number of records that you want in each bucket.
The overhead required for these files is three bytes for each record.
Relative Files with Variable Fixed-Length Control Records
display bsiz = ((rmax +fsiz +3)*rnum)/512
bsizIs the number of blocks per bucket, rounded up to the next higher integer. The result must be in the range 1 through 32.
rmaxIs the maximum size of the data portion of any record in the file (specified by the MAXIMUM_RECORD_SIZE option).
fsizIs the size of the fixed-length control area of records (specified by the FIXED_CONTROL_SIZE option).
rnumIs the number of records you want in each bucket.
The overhead required for these files consists of three bytes, plus the fixed control size, for each record.
By careful calculation of a bucket size, you can improve I/O operations on the file. In general, a bucket size of between four and eight blocks results in good performance for most files. For detailed information on file design and space considerations, see the OpenVMS Record Management Services Reference Manual.
7.2.8. CARRIAGE_RETURN_FORMAT Option
The CARRIAGE_RETURN_FORMAT option indicates that each record in the file is to be preceded by a line feed and followed by a carriage return when the line is written to a carriage-control device such as a terminal or line printer. The format of this option is as follows:
CARRIAGE_RETURN_FORMAT [ (boolean-expression) ]Rules
The CARRIAGE_RETURN_FORMAT option is meaningful only when a file is created.
CARRIAGE_RETURN conflicts with the PRINTER_FORMAT and BLOCK_IO options and with the PRINT file description attribute.
Usage
CARRIAGE_RETURN_FORMAT is the default format for record files.
This type of carriage control is an attribute of the file that is known to the file system; it does not require space within the file's records.
7.2.9. CONTIGUOUS Option
The CONTIGUOUS option specifies that disk space for the associated file be allocated using contiguous blocks on the disk. The format of this option is as follows:
CONTIGUOUS [ (boolean-expression) ]Rules
The CONTIGUOUS option is meaningful only when a file is created.
This option applies only to disk files.
If specified with the CONTIGUOUS_BEST_TRY option, the CONTIGUOUS_BEST_TRY option takes precedence.
Usage
By default, a disk file consists of noncontiguous areas, or extents, on a disk volume. When a file is accessed, the file system must maintain a pointer to each extent. However, there is a maximum number of extents that can be maintained. For very large files that must be accessed quickly, an initial allocation of contiguous space can result in more efficient I/O operations.
The CONTIGUOUS option is generally used with the FILE_SIZE option to specify exactly how much contiguous space is to be allocated for the file when it is first created. When the FILE_SIZE option is not specified, the size of the first allocation is determined by the default cluster size of the disk (usually three to five blocks).
If there is not enough contiguous space on the given volume for the specified size, the UNDEFINEDFILE condition is signaled. If referenced in an ON-unit for this condition, the ONCODE built-in function returns the value associated with the RMS status code RMS$_FULL.
If the file need not be entirely contiguous, use the CONTIGUOUS_BEST_TRY option instead of the CONTIGUOUS option.
Note that both the CONTIGUOUS and CONTIGUOUS_BEST_TRY options apply only to the first allocation of space for the file. If the file is later extended in any way, the new space allocations may or may not be contiguous with the first allocation.
7.2.10. CONTIGUOUS_BEST_TRY Option
This option requests that, if possible, disk space for a new file be allocated in contiguous space on the disk. When the file system allocates space, it tries to place the file in contiguous blocks. The format of this option is as follows:
CONTIGUOUS_BEST_TRY [ (boolean-expression) ]Rules
The CONTIGUOUS_BEST_TRY option is meaningful only when a file is created.
This option applies only to disk files.
CONTIGUOUS_BEST_TRY overrides the CONTIGUOUS option.
7.2.11. CREATION_DATE Option
The CREATION_DATE option lets you specify a date and time field for the file's creation, allowing you to override the default creation date and time. The format of the CREATION_DATE option is as follows:
CREATION_DATE (variable-reference)variable-referenceSpecifies the name of a BIT(64) ALIGNED variable containing an absolute time value in system format. The value specifies the date and time to be used as the file's creation date and time.
Rules
The CREATION_DATE option is meaningful only when a file is created.
Usage
You can obtain the time value required by using the Convert ASCII String to Binary Time system service (SYS$BINTIM).
7.2.12. CURRENT_POSITION Option
The CURRENT_POSITION option specifies that a magnetic tape volume be positioned immediately after the most recently closed file when the next file is created. The format of this option is as follows:
CURRENT_POSITION [ (boolean-expression) ]Rules
The CURRENT_POSITION option is meaningful only when a file is created.
This option applies only to magnetic tape files.
If the REWIND_ON_OPEN option is also selected, it takes precedence over the CURRENT_POSITION option.
Usage
This option lets you close an output file on magnetic tape and proceed to write another file on the same tape immediately after the current file. For example:
DECLARE TAPEFILE FILE RECORD OUTPUT ENV( DEFAULT_FILE_NAME('TAPEFILE:')); OPEN FILE(TAPEFILE) ENV(CURRENT_POSITION) TITLE('TAPE1.FIL'); CLOSE FILE(TAPEFILE); OPEN FILE(TAPEFILE) TITLE('TAPE2.FIL')'
When the second OPEN statement is executed, the tape identified by the logical name TAPEFILE retains the position it had following the CLOSE statement.
7.2.13. DEFAULT_FILE_NAME Option
The DEFAULT_FILE_NAME option specifies default fields for the file specification associated with the PL/I file reference. Its format is as follows:
DEFAULT_FILE_NAME [ (character-expression ) ]character-expressionIs a character-string expression specifying one or more components of an OpenVMS file specification. If no value or a null string is specified, PL/I applies no default values for file specifications.
The string can have a maximum length of 128 characters.
Rules
The DEFAULT_FILE_NAME option is meaningful when a file is created or opened.
When the DEFAULT_FILE_NAME option is not specified, PL/I applies the default file type DAT to file specifications that do not contain a file type.
Usage
For an explanation of the steps that PL/I takes to complete a file specification, including its use of the value of the DEFAULT_FILE_NAME option, see Chapter 4, The File System.
7.2.14. DEFERRED_WRITE Option
The DEFERRED_WRITE option requests that modified I/O buffers not be written back to the disk file until the buffers are needed for other purposes. The format of this option is as follows:
DEFERRED_WRITE [ (boolean-expression) ]Rules
The DEFERRED_WRITE option is meaningful when a file is created or opened. An existing file can be opened for update or opened with the APPEND option.
This option applies only to relative and indexed sequential files.
If a file is opened with the SHARED_READ or SHARED_WRITE option and the DEFERRED_WRITE option, the DEFERRED_WRITE option will be ignored.
Usage
The DEFERRED_WRITE option can provide better I/O performance for output operations, especially when a relative or indexed sequential file is being initially loaded with records, and the records are being added sequentially.
If a system problem occurs when I/O is being performed with the DEFERRED_WRITE option enabled, data may be lost. To ensure the integrity of the file during processing with this option, a PL/I program can call the FLUSH built-in subroutine at critical times to rewrite all buffers. The FLUSH built-in subroutine is described in Chapter 9, File-Handling Built-In Subroutines.
7.2.15. DELETE Option
The DELETE option specifies that the file is to be deleted when it is closed. The format of this option is as follows:
DELETE [ (boolean-expression) ]Rules
The DELETE option can be specified when a file is created, opened, or closed.
Once the DELETE option has been enabled for a file on a particular open, it cannot be disabled.
Usage
When this option is used in conjunction with the SPOOL or BATCH options, the file is marked to be deleted after it is either printed or processed as a batch job.
You can also use this option to delete an existing file. For example:
DECLARE INFILE FILE; OPEN FILE (INFILE) ENVIRONMENT (DELETE); CLOSE FILE(INFILE);
When this CLOSE statement is executed, the OpenVMS file associated with the PL/I file constant INFILE is deleted.
7.2.16. EXPIRATION_DATE Option
The EXPIRATION_DATE option specifies the time at which a magnetic tape or disk file expires. The file cannot be deleted or overwritten until the date specified. The format of the EXPIRATION_DATE option is as follows:
EXPIRATION_DATE (variable-reference)variable-referenceSpecifies the name of a BIT(64) ALIGNED variable that contains an absolute time value or a delta time value in system format. The value specifies the date and time at which a file expires.
Rule
The EXPIRATION_DATE option is meaningful only when a file is created.
Usage
You can obtain the time value required by using the Convert ASCII String to Binary Time system service (SYS$BINTIM).
7.2.17. EXTENSION_SIZE Option
The EXTENSION_SIZE option sets the default extension quantity for a file, that is, the number of blocks to be added to a disk file when a PUT or WRITE operation increases the size of the file beyond its original allocation. The format of the EXTENSION-SIZE option is as follows:
EXTENSION_SIZE(integer-expression)integer-expressionIs a fixed binary integer in the range 0 through 65,535, indicating the extension quantity in 512-byte blocks.
Rules
The EXTENSION_SIZE option is meaningful when a file is created or opened. An existing file can be opened for update or for output with the APPEND option.
This option applies only to disk files.
When an extension size is specified in the opening of an existing file, the extension value is set for the duration of this file opening. When the file is closed, the default set when the file was created is reestablished.
Usage
Using the EXTENSION_SIZE option can improve the efficiency of I/O operations to files that are frequently enlarged.
Each time the addition of a record to a file requires the file system to allocate additional disk extents for the file, RMS allocates the amount of space specified by the EXTENSION_SIZE value. Thus, if you specify a value that is larger than the default that RMS uses, the number of times that the file must be extended will be decreased.
However, if a large extension quantity is specified for a file, and the file does not require the allocated space, the disk space is wasted.
7.2.18. FILE_ID Option
When the FILE_ID option is specified in the opening of an existing file, PL/I uses the value specified in the FILE_ID option to locate the file. The format of the option is as follows:
FILE_ID(variable-reference)variable-referenceSpecifies the name of a 6-element array variable that gives the file identification obtained when the file was created.
The variable must be declared as (6) FIXED BINARY and must be connected.
Rules
The FILE_ID option is valid only when an existing file is opened.
This option conflicts with the TITLE, DEFAULT_FILE_NAME, and FILE_ID_TO options.
If there is no file with the indicated file identification, the UNDEFINEDFILE condition is signaled.
The FILE_ID option cannot be used with DECnet.
This option is provided only for use with the TEMPORARY option.
You must specify the FILE_ID option to reopen a file that was created with the TEMPORARY option.
7.2.19. FILE_ID_TO Option
When a file is created, the FILE_ID_TO option requests PL/I to return the file identification to a user-specified variable. Its format is as follows:
FILE_ID_TO(variable-reference)variable-referenceSpecifies the name of a 6-element array variable to receive the file identification of the created file.
The variable must be declared as (6) FIXED BINARY and must be connected.
Rules
The FILE_ID_TO option is meaningful when a file is created or opened.
This option applies only to disk files.
FILE_ID_TO conflicts with the FILE_ID option.
The FILE_ID_TO option cannot be used with DECnet.
This option is provided only for use with temporary files.
Usage
This option allows you to save the internal file identification of a file created with the TEMPORARY option so that you can access the file later and eventually delete it.
For an example of the FILE_ID_TO and FILE_ID options used for temporary files, see the following description of the TEMPORARY option.
7.2.20. FILE_SIZE Option
The FILE_SIZE option lets you specify the number of blocks to be initially allocated for a file. The format of the FILE_SIZE option is as follows:
FILE_SIZE(integer-expression)integer-expressionIs a value in the range 0 through 4,294,967,295, giving the number of 512-byte blocks. A value of 0 indicates no allocation.
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.
Rules
The FILE_SIZE option is meaningful only when a file is created.
This option applies only to disk files.
Usage
The FILE_SIZE option can optimize I/O operations on large files. When you initially create a file that will require a large amount of space and to which new records will be added frequently, you can reduce the file system overhead required to allocate space each time the file is extended by requesting an initial allocation amount. For example:
DECLARE MONTHLY_TRANSACT FILE RECORD OUTPUT ENVIRONMENT (FILE_SIZE (128));
If you do not specify the FILE_SIZE option, or if you specify a file size of 0, PL/I uses the default extension quantity for the file when the first write or put operation occurs on the file. The default extension quantity is defined in the EXTENSION_SIZE option or supplied by default.
If the specified file size is not a multiple of the cluster size of the disk, the allocation is rounded up to a multiple of the cluster size.
If you allocate more space for a file than it requires, the unused space is wasted.
7.2.21. FIXED_CONTROL_SIZE Option
The FIXED_CONTROL_SIZE option specifies that a file will have a fixed-length control area associated with each variable-length record and specifies the size of the fixed control area. The format of this option is as follows:
FIXED_CONTROL_SIZE(integer-expression)integer-expressionIs an integer expression in the range 0 through 255, indicating the number of bytes in the fixed control field of the record. If you specify a value of 0, PL/I uses the default size of two bytes.
Rules
The FIXED_CONTROL_SIZE option is meaningful only when a file is created.
This option applies only to relative and sequential files with variable-length records.
The FIXED_CONTROL_SIZE option conflicts with the BLOCK_IO and INDEXED options and with the STREAM and UPDATE file description attributes.
You must specify the FIXED_CONTROL_SIZE option to create a file containing records with a fixed-length control area.
Usage
When a file is created with the FIXED_CONTROL_SIZE option, WRITE and REWRITE statements for the file can specify the FIXED_CONTROL_FROM option to write a value into the fixed control area. For example:
DECLARE OUTFILE FILE RECORD OUTPUT ENVIRONMENT ( FIXED_CONTROL_SIZE (2)); OPEN FILE(OUTFILE); WRITE FILE (OUTFILE) FROM (NEWLINE) OPTIONS ( FIXED_CONTROL_FROM(LINE_NUMBER));
If the FIXED_CONTROL_FROM option is not specified when a record is written to a file with fixed control records, PL/I write zeros in the fixed-control area of the record.
7.2.22. FIXED_CONTROL_SIZE_TO Option
The FIXED_CONTROL_SIZE_TO option is used to open an existing file with fixed control records. PL/I returns the length of the fixed control area to a user-specified variable. The format of this option is as follows:
FIXED_CONTROL_SIZE_TO(variable-reference)variable-referenceSpecifies the name of a fixed binary variable to receive the length of the fixed-control area.
The variable must be declared as FIXED BINARY.
Rules
The FIXED_CONTROL_SIZE_TO option is meaningful only when an existing file is opened.
This option applies only to relative and sequential files with variable-length records.
If this option is specified for a file that does not have fixed-control records, PL/I returns a zero to the specified variable.
7.2.23. FIXED_LENGTH_RECORDS Option
The FIXED_LENGTH_RECORDS option specifies that all records in the file are to be of the same length. If you do not specify this option when you create a file, the records in the file will be variable length by default. The format of this option is as follows:
FIXED_LENGTH_RECORDS [ (boolean-expression) ]Rules
The FIXED_LENGTH_RECORDS option is meaningful only when a file is created.
The FIXED_LENGTH_RECORDS option conflicts with the FIXED_CONTROL_SIZE and BLOCK_IO options and with the combination of the STREAM and OUTPUT file description attributes.
Usage
When the FIXED_LENGTH_RECORDS option is specified for the creation of a file, the size of each record can be specified with the MAXIMUM_RECORD_SIZE option. If MAXIMUM_RECORD_SIZE is not specified, PL/I provides a default length of 510 bytes for sequential files and a default length of 480 bytes for relative files.
7.2.24. GROUP_PROTECTION Option
The GROUP_PROTECTION option defines the type of access to be permitted to the file by other users in the owner's group. The format of this option is as follows:
GROUP_PROTECTION (character-expression)character-expressionIs a 1- to 4-character string expression indicating the access privileges to be granted to users in the owner's group. The expression can contain any of the following letters to indicate the access allowed:
Letter Meaning R Read access is allowed. W Write access is allowed. E Execute access is allowed. D Delete access is allowed. The lowercase forms of these letters are also permitted. Letters can be repeated, but the maximum length of the string is 4 characters. All other characters are invalid. If any other character is present in the string, the UNDEFINEDFILE condition is signaled.
Rules
The GROUP_PROTECTION option is meaningful only when a file is created.
If no protection options are specified, PL/I uses the current system and process defaults. If any protection options are specified, the protection for unspecified user categories defaults to no access.
7.2.25. IGNORE_LINE_MARKS Option
The IGNORE_LINE_MARKS option overrides the default manner in which PL/I interprets end-of-line indicators on stream input operations, which is to treat an end-of-line on a stream input operation as a field delimiter in a GET LIST or GET EDIT statement. The format of this option is as follows:
IGNORE_LINE_MARKS [ (boolean-expression) ]Rules
The IGNORE_LINE_MARKS option can be specified when a file is opened.
This option applies only to stream input files; that is, it conflicts with the RECORD, OUTPUT, and UPDATE attributes and with any attributes that imply these attributes.
Usage
When IGNORE_LINE_MARKS is specified for a stream file, an end-of-line terminator such as a carriage return or escape character is ignored, and a GET statement continues to read characters in the input stream until a space, tab, or comma is encountered. For example:
123 Return
456,If these lines are entered in response to a GET statement, the resulting input variable is given the value 123456; the carriage return is ignored, and the GET statement reads input data until the comma is encountered.
7.2.26. INDEX_NUMBER Option
The INDEX_NUMBER option specifies which index is to be used initially to process an indexed sequential file. Its format is as follows:
INDEX_NUMBER(integer-expression)integer-expressionSpecifies the initial index to be used. The value of the expression must be the number of an index for records in the file, where the primary index is 0, the secondary index is 1, and so on.
Rules
The INDEX_NUMBER option can be specified when a file is opened for input or update.
This option is meaningful only for indexed sequential files.
Usage
If the INDEX_NUMBER option is specified for opening an indexed sequential file for sequential access, the records will be accessed in the order of their occurrence in the index specified by the INDEX_NUMBER option.
If the file is opened for keyed access, the INDEX_NUMBER option specifies the initial index to be used. This value can be changed in the following statements:
Any subsequent record I/O statement that specifies the INDEX_NUMBER option
A WRITE statement that specifies the KEYFROM option
Any statement that specifies the RECORD_ID option
In the latter two cases, the index number is set to 0, the primary index.
7.2.27. INDEXED Option
The INDEXED option specifies that a file is an indexed sequential file. The format of this option is as follows:
INDEXED [ (boolean-expression) ]Rules
The INDEXED option is meaningful when an existing file is opened.
This option applies only to indexed sequential files.
INDEXED conflicts with the APPEND, BATCH, BLOCK_IO, FIXED_CONTROL_SIZE, MAXIMUM_RECORD_NUMBER, and PRINTER_FORMAT options and with the PRINT file description attribute.
Usage
The INDEXED option is never required; however, you can use it as a check when you open an existing indexed sequential file so that PL/I will verify the file's organization before opening it.
7.2.28. INITIAL_FILL Option
The INITIAL_FILL option specifies, when an indexed sequential file is opened, that the initial fill value specified when the file was created is to be used.
As an indexed sequential file is initially loaded with records, the fill size specified causes buckets to appear full when they are actually less than full. Thus, room remains in each bucket for subsequent additions to the file.
The format of this option is as follows:.
INITIAL_FILL [ (boolean-expression) ]Rules
The INITIAL_FILL option is meaningful only when an indexed sequential file is initially opened for output.
7.2.29. MAXIMUM_RECORD_NUMBER Option
The MAXIMUM_RECORD_NUMBER option sets, for a relative file, the largest record number that can be written to the file. The format of this option is as follows:
MAXIMUM_RECORD_NUMBER(integer-expression)integer-expressionA numeric expression that must yield an integer result in the range 0 through 2,147,483,647.
If you specify 0, or if this option is not specified, there is no maximum number and no run-time checking of record numbers is performed.
Rules
The MAXIMUM_RECORD_NUMBER option is meaningful only when a file is created.
This option applies only to relative files.
MAXIMUM_RECORD_NUMBER conflicts with the INDEXED option and with the STREAM file description attribute.
Usage
The MAXIMUM_RECORD_NUMBER option lets you specify an upper limit to the values that can be specified for relative record numbers in the file. When a maximum number has been set, then the file system checks the relative number of each record that is written to the file. If a relative record number is not in the correct range, the KEY condition is signaled. If referenced in an ON-unit for this condition, the ONCODE built-in function returns the value associated with the RMS status code RMS$_MRN.
7.2.30. MAXIMUM_RECORD_SIZE Option
The MAXIMUM_RECORD_SIZE option specifies the largest size that records in a file can have. The actual meaning of this option varies according to the type of file:
For a file with fixed-length records, the maximum record size indicates the size of each record in bytes.
For a file with variable-length records, the maximum record size is the size in bytes of the largest record that can be written to the file.
For variable-length records with fixed-length control, the maximum record size does not include the fixed control area size.
For relative files, the maximum record size is used in conjunction with the bucket size to determine the cell size in bytes.
The format of this option is as follows:
MAXIMUM_RECORD_SIZE(integer-expression)integer-expressionIs a numeric expression with values in the range 1 to a maximum determined by record format and file organization, as in the following table.
File Organization Record Format Maximum Sequential Fixed or variable length 32,767 Relative Fixed length 31,998 Relative Variable length 31,998 Indexed sequential Fixed length 16,362 Indexed sequential Variable length 16,360 For variable-length records with a fixed-length control area, the size of the fixed control area must be subtracted from the maximum value allowed.
A value of 0 indicates that there is no user-defined limit to the size of records.
If the value is out of range, the UNDEFINEDFILE condition is signaled.
Rules
The MAXIMUM_RECORD_SIZE option is meaningful only when a file is created. If not specified, PL/I provides a default length based on the file organization and record format as follows:
| File Organization | Record Format | Default |
|---|---|---|
| Sequential | Fixed length | 512 |
| Sequential | Variable length | 510 |
| Relative | Fixed or variable length | 480 |
If the file has variable with fixed-length control records, the size of the fixed control area is subtracted from the default value listed.
7.2.31. MULTIBLOCK_COUNT Option
The MULTIBLOCK_COUNT option specifies the number of blocks to be allocated in each internal buffer for operations on a sequential disk file. Its format is as follows:
MULTIBLOCK_COUNT(integer-expression)integer-expressionIs a fixed binary expression in the range 0 through 127, indicating the number of blocks to be allocated to each buffer. If 0 is specified, PL/I uses the system default. You can determine the current system default by entering the DCL command SHOW RMS_DEFAULT. Use the SET RMS_DEFAULT command to establish a new default value, if desired.
If the value is not within the required range, the UNDEFINEDFILE condition is signaled.
Rules
The MULTIBLOCK_COUNT option is meaningful when a file is created or opened.
This option applies only to sequential disk files. It is ignored if the BLOCK_IO option is specified or if the file is not a sequential disk file.
Usage
The MULTIBLOCK_COUNT option can optimize I/O operations on sequential disk files. By default, RMS transfers data in 512-byte disk blocks. To improve I/O access time, you can specify a multiple of 512-byte blocks to specify that a larger number of blocks be transferred with each input or output operation. In general, a multiblock count of between 12 and 16 results in good performance for sequential I/O.
The MULTIBLOCK_COUNT option can also be used with the MULTIBUFFER_COUNT option to request a specified number of I/O buffers, each of which can contain the given number of blocks.
7.2.32. MULTIBUFFER_COUNT Option
The MULTIBUFFER_COUNT option specifies the number of buffers to be allocated for file operations; it has the following effects, depending on the organization of the file:
For relative and indexed sequential files, it results in a cache of buckets that can improve random access.
For sequential files, multiple buffers allow throughput to be increased on file transfers when either the READ_AHEAD or the WRITE_BEHIND option is also selected. If neither of these options is specified, the MULTIBUFFER_COUNT option is meaningless for sequential files.
Its format is as follows:
MULTIBUFFER_COUNT(integer-expression)integer-expressionSpecifies a value in the range -128 through 127, indicating the number of buffers to be allocated; RMS uses the absolute value of the field. If 0 is specified, PL/I applies the current RMS default. This default can be set with the DCL command SET RMS_DEFAULT; its current value can be determined with the command SHOW RMS_DEFAULT.
If either the READ_AHEAD or the WRITE_BEHIND option is specified and the MULTIBUFFER_COUNT option is not specified, PL/I uses the RMS default value of two buffers.
Rules
The MULTIBUFFER_COUNT option is meaningful when a file is created or opened.
This option applies only to disk files.
This option has no effect if BLOCK_IO is specified.
Usage
When you use the MULTIBUFFER_COUNT option, it decreases the number of actual data transfers and thus increases a program's execution speed. For example:
OPEN FILE(REL_FILE) ENVIRONMENT(READ_AHEAD, MULTIBLOCK_COUNT(4) , MULTIBUFFER_COUNT(4));
This option can be specified for sequential, relative, or indexed sequential files. For inserting records in an indexed sequential file, a good rule of thumb is to specify one buffer for each index in use, plus two or more buffers for data. Thus, an indexed sequential file with a primary key and two alternate keys could be opened with the following ENVIRONMENT specification:
ENVIRONMENT (MULTIBUFFER_COUNT(5))
This option specifies five buffers.
Multibuffering is also effective for sequential files when combined with the ENVIRONMENT options READ_AHEAD or WRITE_BEHIND. These options are described individually in this chapter.
7.2.33. NO_SHARE Option
The NO_SHARE option prohibits sharing of the data in a file. The format of the NO_SHARE option is as follows:
NO_SHARE [ (boolean-expression) ]Rules
The NO_SHARE option is meaningful when a file is created or opened.
This option applies only to disk files.
NO_SHARE conflicts with the SHARED_READ and SHARED_WRITE options.
If the specified file is already opened for sharing, the UNDEFINEDFILE condition is signaled.
Usage
By default, the NO_SHARE option is enabled when a file is opened for output or update. This option is disabled when a file is opened for input.
7.2.34. OWNER_GROUP Option
The OWNER_GROUP option overrides the default group number in the user identification code (UIC) associated with the file's owner. The group number, together with the member number, defines the ownership of the file and provides the values against which protection is applied. Its format is as follows:
OWNER_GROUP(integer-expression)integer-expressionIs an integer value in the range 0 through 16383 (decimal).
Rules
The OWNER_GROUP option is meaningful only when a file is created.
If the OWNER_GROUP option is not specified, PL/I uses the group number in the current UIC.
The OWNER_GROUP option conflicts with the OWNER_ID option.
To specify an owner UIC for a file that is different from the UIC under which the current program is executing, the process must have the SYSPRV user privilege or a system UIC.
Usage
Note that although the value can be specified to PL/I in decimal, the OpenVMS system always displays UICs in octal format.
Following is an example of a program using the OWNER_GROUP and the OWNER_MEMBER options to define the ownership of a file. Note the use of the DECODE built-in function to obtain octal numbers for the UIC.
OWNER: PROCEDURE OPTIONS(MAIN); DCL TEST_FILE STREAM OUTPUT FILE; OPEN FILE(TEST_FILE) ENVIRONMENT(OWNER_GROUP(DECODE('214',8)), OWNER_MEMBER(DECODE('10223',8))); PUT FILE(TEST_FILE) LIST('This file is owned by UIC [214,10223].'); CLOSE FILE(TEST_FILE); END OWNER;
7.2.35. OWNER_ID Option
The OWNER_ID option overrides the default owner of a file. This option combines the capabilities of the OWNER_GROUP and OWNER_MEMBER options. In addition, this option allows the specification of identifiers that are not true UICs, which is not possible with the other two options. Its format is as follows:
OWNER_ID(integer-expression)integer-expressionIs any FIXED BINARY value.
Rules
The OWNER_ID option is meaningful only when a file is created.
If the OWNER_ID option is not specified, PL/I uses the current process UIC.
This option conflicts with both the OWNER_GROUP and the OWNER_MEMBER options.
Usage
Following is an example of a program using the OWNER_ID option:
/* * This program example creates a file owned by the identifier TEST. (Note * that the process running this program must hold the identifier with the * RESOURCE attribute or the file creation will fail.) */ %REPLACE IDENTIFIER BY 'TEST'; OWNER_ID: PROCEDURE OPTIONS(MAIN); %INCLUDE $KGBDEF; %INCLUDE $STSDEF; %INCLUDE SYS$ASCTOID; DCL TEST_FILE STREAM OUTPUT FILE; DCL IDENTIFIER_VALUE FIXED BINARY; DCL KGB_BITS BIT(32) ALIGNED; /* * Get the value of the identifier. (Note: The fact that the value * translates successfully does not mean that the current process * holds the identifier. */ STS$VALUE = SYS$ASCTOID( IDENTIFIER, IDENTIFIER_VALUE, KGB_BITS ); IF ~STS$SUCCESS THEN SIGNAL VAXCONDITION(STS$VALUE); /* * Does the identifier have the resource attribute? (Note: If you * want to determine whether this process holds the identifier with the * resource attribute, you must use the SYS$FIND_HOLDER or SYS$CHKPRO * system services.) */ IF (KGB_BITS & KGB$M_RESOURCE) = '0'b THEN PUT LIST('The identifier ' || IDENTIFIER || ' does not have the RESOURCE attribute.'); OPEN FILE(TEST_FILE) ENVIRONMENT(OWNER_ID(IDENTIFIER_VALUE)); PUT FILE(TEST_FILE) LIST('This file is owned by the identifier ' || IDENTIFIER || '.'); CLOSE FILE(TEST_FILE); END OWNER_ID;
7.2.36. OWNER_MEMBER Option
The OWNER_MEMBER option overrides the default member number in the user identification code (UIC) associated with the file's owner. The member number of a file's owner, together with the group number, provides protection for the file. Its format is as follows:
OWNER_MEMBER(integer-expression)integer-expressionIs a numeric value in the range 0 through 65535 (decimal).
Rules
The OWNER_MEMBER option is meaningful only when a file is created.
If the OWNER_MEMBER option is not specified, PL/I uses the member number in the current UIC.
The OWNER_MEMBER option conflicts with the OWNER_ID option.
To specify an owner UIC for a file that is different from the UIC under which the current program is executing, the process must have the SYSPRV user privilege or a system UIC.
Usage
Note that although the value can be specified to PL/I in decimal, the OpenVMS system always displays UICs in octal format.
See the section on the OWNER_GROUP option for an example of a program using the OWNER_MEMBER option.
7.2.37. OWNER_PROTECTION Option
The OWNER_PROTECTION option defines the type of access to be permitted to the file by the file's owner and by other users with the same user identification code (UIC). The format of this option is as follows:
OWNER_PROTECTION(character-expression)character-expressionIs a 1- to 4-character string expression indicating the access privileges to be granted to the file's owner (and any other users who have the same UIC). The character-string expression can contain any of the following letters to indicate the access allowed:
Letter Meaning R Read access is allowed. W Write access is allowed. E Execute access is allowed. D Delete access is allowed. The lowercase forms of these letters are also permitted. Letters can be repeated, but the maximum length of the string is 4 characters. All other characters are invalid. If any other character is present in the string, the UNDEFINEDFILE condition is signaled.
Rules
The OWNER_PROTECTION option is meaningful only when a file is created.
If no protection options are specified, PL/I applies the current system or process default protection. If any protection options are specified, the protection for unspecified user categories defaults to no access.
7.2.38. PRINTER_FORMAT Option
The PRINTER_FORMAT option specifies that the records in the file contain printing and carriage-control information in the fixed control area. The format of this option is as follows:
PRINTER_FORMAT [ (boolean-expression) ]Rules
The PRINTER_FORMAT option is meaningful only when a file is created.
The FIXED_CONTROL_SIZE option should be specified with the PRINTER_FORMAT option. The size of the fixed control area must be two to six bytes. If FIXED_CONTROL_SIZE is not specified, the size of the fixed control area defaults to two bytes.
This option applies only to relative or sequential files.
PRINTER_FORMAT conflicts with the STREAM file description attribute and with the following ENVIRONMENT options:
CARRIAGE_RETURN_FORMAT
FIXED_LENGTH_RECORDS
BLOCK_IO
Usage
This option indicates that a file is in printer format, that is, the fixed control area of each record contains carriage-control information. Printer file format provides more explicit carriage control than the default type of carriage control, called carriage return format. Printer format is particularly useful in formatting a printed listing.
Note that format items are implemented in the following way:
Pages are started with a form feed.
Blank lines (created with the SKIP option) are totally blank.
Tabs are counted as spaces.
Table 7.2, “Printer File Format Carriage Control” summarizes coding specifications for the fixed-length control area for files with printer format. The first byte in the fixed control area is called the prefix byte: it determines the carriage control to be performed before writing the record. The second byte is the postfix byte: it determines the carriage control to be performed after writing the record. The values shown in Table 7.2, “Printer File Format Carriage Control” have the same meanings in either byte; the bytes are interpreted separately.
| Bit 7 | Bits 0-6 | Meaning | ||
| 0 | 0 | No carriage control is specified, that is, NULL. | ||
| 0 | 1-7F | Bits 0 through 6 are a count of new lines (line feeds followed by carriage return). | ||
| Bit 7 | Bit 6 | Bit 5 | Bits 0-4 | Meaning |
| 1 | 0 | 0 | 0-1F | Output the ASCII control character specified by the configuration of bits 0 through 4 (7-bit character set). |
| 1 | 1 | 0 | 0-1F | Output the ASCII control character specified by the configuration of bits 0 through 4, which are translated as ASCII characters 128 through 159 (8-bit character set). |
| 1 | 1 | 1 | 0-1F | Reserved. |
Example 7.1, “Explicit Carriage Control” illustrates a procedure that uses explicit carriage control. The following notes are keyed to this program:
- ❶
The structures LINE_FEEDS and CARRIAGE_CONTROL define bit fields corresponding to the fields shown in Table 7.2, “Printer File Format Carriage Control”. The fields that must be set are initialized.
- ❷
The procedure declares and defines values for NEW_LINE and NEW_PAGE. These 8-bit strings correspond to the fields within the structure CARRIAGE_CONTROL.
Note the use of the POSINT built-in function to define these fields. The POSINT built-in function must be used so that the bit string value is treated as a positive integer.
- ❸
The output file PRINTFILE is declared with the RECORD and OUTPUT attributes and with ENVIRONMENT options FIXED_CONTROL_SIZE and PRINTER_FORMAT.
- ❹
The first line is output with no carriage control. Note that any subsequent lines printed without carriage control would result in overprinting.
- ❺
The procedure uses the POSINT built-in function to specify an integer value for the 7-bit field LINE_FEEDS.COUNT. Then, the variable CONTROL_FIELD is assigned two 1-byte values:
The prefix byte specifies the number of line feeds to precede the line when it is output. This value is specified by using the STRING built-in function to concatenate the bit fields in LINE_FEEDS.
The postfix byte specifies a carriage return following the output record. This value is specified using the variable NEW_LINE.
- ❻
The variable CONTROL_FIELD is assigned new values for the prefix and postfix bytes to output another record. This prefix byte specifies a new page; the postfix byte specifies a new line.
- ❼
The line is output.
- ❽
The file is spooled to the system printer when it is closed.
PRINTER_FORMAT_EXAMPLE: PROCEDURE OPTIONS(MAIN); /* * Declare structure definitions for carriage-control bit fields * and a FIXED BIN(15) variable for the fixed control area */ /* ❶ */ DECLARE 1 LINE_FEEDS STATIC, 2 COUNT BIT (7), /* Contains count of line feeds */ 2 INDICATOR BIT(1) INIT('0'B), /* Must be zero */ 1 CARRIAGE_CONTROL STATIC, 2 CODE BIT(5), /* Bits 0-4 ASCII code for action */ 2 FILLER BIT(2) INIT('00'b), /* Bits 5 and 6 */ 2 EXPLICIT BIT(1) INIT('1'B), /* Bit 7 must be set */ CONTROL_FIELD BIT(16) ALIGNED; /* * Set up variables for form feeds and carriage returns */ DECLARE (NEW_LINE,NEW_PAGE) BIT(8); /* ❷ */ /* * Declare PRINTFILE with character-string variable for I/O */ DECLARE PRINTFILE RECORD OUTPUT FILE ENV( FIXED_CONTROL_SIZE(2), /* ❸ */ PRINTER_FORMAT), PRINTREC CHARACTER(80) VARYING; /* * Set up the NEW_PAGE and NEW_LINE variables using the * CARRIAGE_CONTROL structure as a template. */ POSINT(CODE) = 12; /* Assign ASCII code for form feed */ NEW_PAGE = STRING(CARRIAGE_CONTROL); POSINT(CODE) = 13; /* Assign ASCII code for CR */ NEW_LINE = STRING(CARRIAGE_CONTROL); OPEN FILE(PRINTFILE); /* * Output first line with no carriage control */ PRINTREC = 'Output first line with no carriage control'; /* ❹ */ WRITE FILE(PRINTFILE) FROM(PRINTREC); /* * Prepare to output five line feeds followed by a new line */ POSINT(LINE_FEEDS.COUNT) = 5; /* assign 5 to LINE_FEEDS.COUNT */ /* ❺ */ CONTROL_FIELD = STRING(LINE_FEEDS) || NEW_LINE; PRINTREC = 'Record preceded by 5 line feeds '; WRITE FILE(PRINTFILE) FROM (PRINTREC) OPTIONS( FIXED_CONTROL_FROM(CONTROL_FIELD)); /* * Prepare to output a page eject followed by a new line */ CONTROL_FIELD = NEW_PAGE || NEW_LINE; /* ❻ */ PRINTREC = 'New page'; WRITE FILE(PRINTFILE) FROM(PRINTREC) OPTIONS( /* ❼ */ FIXED_CONTROL_FROM(CONTROL_FIELD)); CLOSE FILE(PRINTFILE) ENV(SPOOL); /* ❽ */ END PRINTER_FORMAT_EXAMPLE;
7.2.39. READ_AHEAD Option
The READ_AHEAD option requests the overlapping of reading records into buffers with computing operations. This option, used in conjunction with the MULTIBUFFER_COUNT option, can increase the efficiency of I/O operations to disk files. PL/I enables this option by default. The format of this option is as follows:
READ_AHEAD [ (boolean-expression) ]Rules
The READ_AHEAD option is meaningful when an existing file is opened for input or for update.
This option applies only to sequential disk files.
Usage
When you use the READ_AHEAD option, you can specify the number of buffers to be used in the MULTIBUFFER_COUNT option. When READ_AHEAD is in effect and no multibuffer count is specified, RMS uses two buffers by default.
When READ_AHEAD is enabled, the data transfer and the reading ahead are transparent to the PL/I program.
7.2.40. READ_CHECK Option
The READ_CHECK option specifies that all input transfers of data between a program and a disk device be followed by a comparison operation to ensure that the data was transferred intact. The format of this option is as follows:
READ_CHECK [ (boolean-expression) ]Rules
The READ_CHECK option is meaningful when a file is created or opened. An existing file can be opened for input or for update.
Usage
This option is useful for applications that must verify all I/O operations to ensure that data was successfully transferred. However, use of this option decreases the speed and efficiency of I/O operations.
If READ_CHECK is specified when a file is created, READ_CHECK is the default for all subsequent openings of the file, unless explicitly disabled.
7.2.41. RECORD_ID_ACCESS Option
The RECORD_ID_ACCESS option indicates that the records in a file will be accessed randomly, using the internal identification of the records. The format of this option is as follows:
RECORD_ID_ACCESS [ (boolean-expression) ]Rules
The RECORD_ID_ACCESS option is meaningful when a file is created or opened.
This option applies only to disk files.
The RECORD_ID_ACCESS option conflicts with the BLOCK_IO option.
Usage
You must open a file with this option to use the RECORD_ID_TO and RECORD_ID options of the record I/O statements. These options are described in Chapter 8, Input/Output Statement Options.
When a file is opened with the RECORD_ID_ACCESS option, access by record identification can be mixed with sequential access or access by key during this opening. However, a statement cannot specify a record both by key and by record identification.
7.2.42. RETRIEVAL_POINTERS Option
The RETRIEVAL_POINTERS option specifies the number of extent pointers to be maintained in main memory for file access. Each pointer provides access to a separate extent in the file; increasing the number of pointers for a noncontiguous file can increase the speed with which records are accessed during I/O operations. Its format is as follows:
RETRIEVAL_POINTERS(integer-expression)integer-expressionIs a fixed binary expression in the range -1 through 127. A value in the range of 1 through 127 indicates the number of pointers. If you specify -1, the file system maps as much of the file as possible. If the option is not specified, or if the expression has a value of 0, the file system uses the default number established when the volume was initialized or mounted.
Rules
The RETRIEVAL_POINTERS option is meaningful when a file is created or opened.
Usage
When a disk is initialized, the default window size is set by the /WINDOW qualifier of the DCL command INITIALIZE. You can override this value for the opening of a specific file by specifying the RETRIEVAL_POINTERS option to increase the speed with which records can be accessed.
However, you should avoid specifying a value that is too large. Space for the pointers is allocated from system space, and a large number of pointers could have an adverse effect on system performance.
7.2.43. REVISION_DATE Option
The REVISION_DATE option lets you specify a date and time field for the file's revision, allowing you to override the default revision date and time. The format of this option is as follows:
REVISION_DATE (variable-reference)variable-referenceSpecifies the name of a BIT(64) ALIGNED variable containing an absolute time value in system format. The value specifies the date and time to be used as the file's revision date and time.
Rules
The REVISION_DATE option is meaningful only when the file is closed.
Usage
You can obtain the time value required by using the Convert ASCII String to Binary Time system service (SYS$BINTIM).
7.2.44. REWIND_ON_CLOSE Option
The REWIND_ON_CLOSE option specifies, for a file on a magnetic tape volume, that the volume is to be rewound when the file is closed. The format of this option is as follows:
REWIND_ON_CLOSE [ (boolean-expression) ]Rules
The REWIND_ON_CLOSE option can be specified when a file is created, opened, or closed.
This option applies only to magnetic tape files.
REWIND_ON_CLOSE takes precedence over the CURRENT_POSITION option.
7.2.45. REWIND_ON_OPEN Option
The REWIND_ON_OPEN option specifies, for a file on a magnetic tape volume, that the volume is to be rewound when the file is created or opened. The format of this option is as follows:
REWIND_ON_OPEN [ (boolean-expression) ]Rules
The REWIND_ON_OPEN option is meaningful when a file is created or opened.
This option applies only to magnetic tape files.
REWIND_ON_OPEN takes precedence over the CURRENT_POSITION option.
Usage
Magnetic tape file positioning is described in Chapter 6, Record Input/Output.
7.2.46. SCALARVARYING Option
The SCALARVARYING option specifies that character strings with the VARYING attribute be read and written in strict accordance with the PL/I ANSI standard. Its format is as follows:
SCALARVARYING [ (boolean-expression) ]Rules
The SCALARVARYING option is meaningful when a file is created or opened.
SCALARVARYING conflicts with the STREAM file description attribute.
Usage
The SCALARVARYING option has the following effect on I/O operations involving VARYING character-string variables:
When a record is written from a varying-length character string, the entire storage of the string is written, including the word containing the string's current length.
When a record is read into a varying-length character-string variable, the first word of the record is read into the variable's current length field.
Thus, records to be read into or from variables with the VARYING attribute should be images of a varying character string-including the 2-byte count field at the beginning of the string.
When SCALARVARYING is not specified, character-string variables with the VARYING attribute are handled so as to facilitate reading and writing files with variable-length records. The rules are as follows:
On an input operation, the entire record read into the variable is treated as a character string and assigned to the variable. Thus, the current length of the variable is always set to the record length of the record read, unless truncation occurs.
On an output operation, only the characters of the string's current value are written.
For strings with the VARYING attribute that are embedded in arrays or structures, the entire storage is always read or written.
When a file is to be read with SCALARVARYING in effect, the target variable must be declared CHARACTER VARYING, and the length of the target variable must match the record length of each record in the file, minus two bytes. If the length does not match, the ERROR condition is signaled.
The following example illustrates reading a file with the SCALARVARYING option (presumably the file was created with the SCALARVARYING option in effect):
DECLARE EOF BIT(1) ALIGNED INITIAL('0'B); DECLARE STRING CHARACTER(80) VARYING, INFILE FILE RECORD INPUT; OPEN FILE(INFILE) ENVIRONMENT(SCALARVARYING); ON ENDFILE(INFILE) EOF = '1'B; READ FILE(INFILE) INTO(STRING); DO WHILE (^EOF); PUT SKIP LIST(LENGTH(STRING),STRING); READ FILE(INFILE) INTO(STRING); END;
The file defined as INFILE must have 82-byte records: the first two bytes of each record must contain the length of the data within the record. This READ statement reads 82 bytes, and uses the first two as the length and contents of each string.
7.2.47. SHARED_READ Option
The SHARED_READ option specifies that other users who have concurrent access to the file can read records in it. The format of this option is as follows:
SHARED_READ [ (boolean-expression) ]Rules
The SHARED_READ option is meaningful when a file is created or opened.
This option applies to relative and indexed sequential files.
SHARED_READ conflicts with the NO_SHARE option.
Usage
By default, the SHARED_READ option is disabled when a file is opened for output or update; that is, sharing is not allowed by default if anyone is writing to the file. SHARED_READ is enabled when a file is opened for input, that is, sharing is allowed if no one is writing to the file.
7.2.48. SHARED_WRITE Option
The SHARED_WRITE option specifies that other users who have concurrent access to the file can write, update, and delete records in the file. The format of this option is as follows:
SHARED_WRITE [ (boolean-expression) ]Rules
The SHARED_WRITE option is meaningful when a file is created or opened.
This option applies to sequential, relative, and indexed sequential files.
SHARED_WRITE conflicts with the NO_SHARE option.
If SHARED_READ and SHARED_WRITE are both specified, the effect is the same as if only SHARED_WRITE were specified.
Usage
By default, the SHARED_WRITE option is disabled.
7.2.49. SPOOL Option
The SPOOL option requests that the file be submitted to the system printer job queue when it is closed. The format of this option is as follows:
SPOOL [ (boolean-expression) ]Rules
The SPOOL option can be specified when a file is created, opened, or closed.
This option applies to stream files as well as to record files of any file organization.
Once the SPOOL option has been specified for a particular file and opening, it cannot be disabled.
Usage
If you specify the DELETE option in conjunction with the SPOOL option, the file is submitted to the queue SYS$PRINT when it is closed and marked to be deleted after printing.
You can control the queue to which the file is submitted by using the DEFINE command to equate the logical name SYS$PRINT with the name of a specific queue before running the program. For example:
$DEFINE SYS$PRINT LPC0:$RUN PRINTER
If the PL/I program PRINTER closes a file with the SPOOL option, the file is queued to LPC0: (the printer device).
7.2.50. SUPERSEDE Option
The SUPERSEDE option specifies that if a file already exists with the same name, type, and version number as the file specified, the existing file should be replaced. The format of this option is as follows:
SUPERSEDE [ (boolean-expression) ]Rules
The SUPERSEDE option is meaningful only when a file is created.
SUPERSEDE conflicts with the APPEND option.
Usage
By default, the file system creates a new file and assigns it a new version number whenever a file is opened for output. Consequently, if a file specification does not include a version number, many versions of a file may be created. If the file's TITLE option or DEFAULT_FILE_NAME option specifies an explicit version number, the ERROR condition is signaled if a file with that version number already exists.
In some cases, you may want to specify an explicit version number to ensure that a single version of a specific file be maintained. In these cases, specify the SUPERSEDE option in conjunction with a TITLE value or DEFAULT_FILE_NAME value to ensure that multiple versions of the file are not created.
7.2.51. SYSTEM_PROTECTION Option
The SYSTEM_PROTECTION option defines the type of access to be permitted to the file by users with system user identification codes (UICs). The format of this option is as follows:
SYSTEM_PROTECTION(character-expression)character-expressionIs a 1- to 4-character string expression indicating the access privileges to be granted to users with system UICs or with the SYSPRV user privilege. The character-string expression can contain any of the following letters to indicate the access allowed:
Letter Meaning R Read access is allowed. W Write access is allowed. E Execute access is allowed. D Delete access is allowed. The lowercase forms of these letters are also permitted. Letters can be repeated, but the maximum length of the string is 4 characters. All other characters are invalid. If any other character is present in the string, the UNDEFINEDFILE condition is signaled.
Rules
The SYSTEM_PROTECTION option is meaningful only when a file is created.
If no protection options are specified, PL/I applies the current system and process defaults. If any protection options are specified, the protection for unspecified user categories defaults to no access.
7.2.52. TEMPORARY Option
The TEMPORARY option creates a temporary file with no directory entry. The format of this option is as follows:
TEMPORARY [ (boolean-expression) ]Rules
The TEMPORARY option is meaningful only when a file is created.
TEMPORARY conflicts with the TITLE and the DEFAULT_FILE_NAME options.
Usage
When you create a file with the TEMPORARY option, the file system does not create a directory entry for the file. A file thus created can be used during the execution of the program and deleted on completion, without the overhead required to create and remove the directory entry.
The file can be deleted when it is closed or, if needed later, can be deleted after it has been reused. You specify deletion by using the DELETE option when you open, reopen, or close the file.
However, because no directory entry is created for a temporary file, the file can be reaccessed only by its internal file identification. You can obtain this identification by specifying the FILE_ID_TO option when the file is created. For example:
DECLARE WORKFILE FILE OUTPUT SEQUENTIAL, WORKFILE_ID (6) FIXED BINARY; OPEN FILE(WORKFILE) ENVIRONMENT (TEMPORARY, FILE_ID_TO(WORKFILE_ID)); ⋮ CLOSE FILE(WORKFILE); ⋮ OPEN FILE (WORKFILE) ENVIRONMENT ( FILE_ID(WORKFILE_ID), DELETE);
These statements declare the file WORKFILE, open it with the FILE_ID_TO option, close it, and later reopen it, using the FILE_ID option and specifying the file identification obtained when the file was first opened. The second OPEN statement also specifies the DELETE option of ENVIRONMENT, so that the file is deleted when it is subsequently closed.
Note that the FILE_ID and the FILE_ID_TO options, which are necessary for reaccessing a temporary file, cannot be used across the DECnet.
The TEMPORARY option is also useful in conjunction with the BATCH or SPOOL options. For example, if you create a file that is to be printed but that can be deleted after printing, you can specify it as follows:
DECLARE PRINTFILE FILE PRINT ENVIRONMENT ( SPOOL, TEMPORARY, DELETE);
When this file is closed, it is automatically queued for printing. Once it is printed, it is deleted.
7.2.53. TRUNCATE Option
The TRUNCATE option specifies that any unused space allocated for a file be deallocated when the file is closed. The file is truncated to its logical end-of-file. The format of this option is as follows:
TRUNCATE [ (boolean-expression) ]Rules
The TRUNCATE option can be specified when a file is created, opened, or closed. An existing file can be opened for update or opened with the APPEND option.
This option applies only to sequential files.
Once the TRUNCATE option has been specified for a file on a particular open, it cannot be disabled.
Usage
You can specify this option to conserve disk space. If a file's allocation is greater than its contents require, and if the file is not expected to increase in size, you may want to use this option to reclaim the allocated, but unused, space.
7.2.54. USER_OPEN Option
The USER_OPEN option allows you to access RMS facilities not explicitly available in PL/I by writing a function that controls the opening of the file. Specifying the USER_OPEN option causes the run-time library to call your function to open the file instead of calling RMS to open it according to its normal defaults. The format of this option is as follows:
USER_OPEN (entry-name)entry-nameAn entry variable or entry constant.
When the OPEN statement is executed, the run-time library sets up the RMS file access block (FAB) and the record access block (RAB), as well as its own internal data structures. These blocks transmit requests for file and record operations to RMS; they also return the data contents of files, information about file characteristics, and status codes. For more information on the RAB and the FAB, see the OpenVMS Record Management Services Reference Manual.
In order, the three parameters passed to the user-open function by the run-time library are as follows:
FAB address
RAB address
Open-flag, which is passed as a longword 1 if the file exists (in which case SYS$OPEN should be called); if the file does not exist, a longword zero is passed (in which case SYS$CREATE should be called)
Rules
The function must call SYS$OPEN or SYS$CREATE.
The status of the call must be returned.
The function can modify the FAB or the RAB, or both.
The function can store FAB and RAB values in program variables.
The structures for the FAB and the RAB that are found in PLI$STARLET (modules $FABDEF and $RABDEF) should be used when you manipulate the FAB and the RAB.
The USER_OPEN option should be used only when there is no way to do what you want within PL/I.
Note
Your user-open function may have to be changed when new run-time libraries are released.
Usage
The following example shows a PL/I program that creates a file 1000 blocks long.
/* * This program allocates 1000 blocks to the file new.tmp. */ OPEN_TEST: PROC OPTIONS(MAIN); DCL F FILE OUTPUT; OPEN FILE(F) ENVIRONMENT(USER_OPEN(MY_OPEN)) TITLE('NEW.TMP'); RETURN; /* * This function sets the appropriate bit in the FAB to allocate * 1000 blocks for the file. */ MY_OPEN:PROC(FAB,RAB,OPEN_FLAG) RETURNS(FIXED BIN); %INCLUDE $FABDEF; %INCLUDE $RABDEF; DCL 1 FAB LIKE FABDEF; DCL 1 RAB LIKE RABDEF; DCL OPEN_FLAG FIXED BIN; DCL STATUS FIXED BIN; %INCLUDE SYS$OPEN; %INCLUDE SYS$CREATE; /* * Store the allocation quantity. */ FAB.FAB$L_ALQ = 1000; /* * Call sys$open or sys$create and return its status to the Run-Time * Library. */ IF OPEN_FLAG = 1 THEN STATUS = SYS$OPEN(FAB,,); ELSE STATUS = SYS$CREATE(FAB,,,); RETURN(STATUS); END MY_OPEN; END OPEN_TEST;
7.2.55. WORLD_PROTECTION Option
The WORLD_PROTECTION option defines the type of access to be permitted to the file by users who are not in the owner's group and who do not have system user identification codes. The format of this option is as follows:
WORLD_PROTECTION(character-expression)character-expressionIs a 1- to 4-character string expression indicating the access privileges to be granted to users in the world category. The character-string expression can contain any of the following letters to indicate the access allowed:
Letter Meaning R Read access is allowed. W Write access is allowed. E Execute access is allowed. D Delete access is allowed. The lowercase forms of these letters are also permitted. Letters can be repeated, but the maximum length of the string is four characters. All other characters are invalid. If any other character is present in the string, the UNDEFINEDFILE condition is signaled.
Rules
The WORLD_PROTECTION option is meaningful only when a file is created.
If no protection options are specified, PL/I uses the current system and process defaults. If any protection options are specified, the default protection for unspecified user categories is no access.
7.2.56. WRITE_BEHIND Option
The WRITE_BEHIND option requests the file system to overlap the writing of buffers with computing operations. The format of this option is as follows:
WRITE_BEHIND [ (boolean-expression) ]Rules
The WRITE_BEHIND option is meaningful when a file is created or opened. An existing file can be opened either for update or for output with the APPEND option.
This option applies only to sequential files; it is ignored for unit record devices.
Usage
When you use the WRITE_BEHIND option, you can specify the number of buffers to be used in the MULTIBUFFER_COUNT option. If you specify WRITE_BEHIND and do not specify a multibuffer count, RMS uses two buffers by default.
When the WRITE_BEHIND option is in effect, there is no way for the program to determine when a buffer has been written to disk. To ensure the integrity of a file that is being processed with the WRITE_BEHIND option, you can use the FLUSH built-in subroutine to periodically write all buffers back to disk. The FLUSH built-in subroutine is described in Chapter 9, File-Handling Built-In Subroutines.
7.2.57. WRITE_CHECK Option
The WRITE_CHECK option specifies that all write transfers of data between a program and a disk device be followed by a compare operation to ensure that the data was transferred intact. The format of this option is as follows:
WRITE_CHECK [ (boolean-expression) ]Rules
The WRITE_CHECK option is meaningful when a file is created or opened. An existing file can be opened either for update or for output with the APPEND option.
Usage
This option is useful for applications that must verify all I/O operations, to ensure that data was successfully transferred. However, use of this option decreases the speed and efficiency of I/O operations.
If WRITE_CHECK is specified when a file is created, WRITE_CHECK is the default for all subsequent openings of the file, unless explicitly disabled.
7.3. ENVIRONMENT Options for File Protection and File Sharing
This section discusses the ENVIRONMENT options that take advantage of special RMS processing options for file protection and file sharing.
7.3.1. File Protection
Each user who is authorized to use the system is assigned a user identification code (UIC) by the system manager. When a PL/I program creates a file, the current UIC associated with the process executing the program defines the file's ownership.
Based on this UIC, called the owner UIC, the file system defines the protection of the file in terms of which other users on the system can access the file and what operations they can perform on the file. The other users in the system are defined as follows:
Owner-Any other process that has the same UIC as that established as the file's owner is also the owner of a file.
Group-A process that has the same group number in its UIC is a member of the owner's group.
System-A process that has a group number in the system-defined range or that has the SYSPRV user privilege is in the system user category.
World-All jobs and processes that do not fall into the other three categories belong to the world category.
The types of access privileges defined for a file are as follows:
You can explicitly control the protection applied to a file in two ways:
Specify the file's ownership.
Specify the type of access allowed each category of user.
In a PL/I program, you can specify a file's ownership and protection when you create the file.
7.3.1.1. Defining a File's Ownership
When you specify the ENVIRONMENT attribute for a file you are creating in a PL/I program, you can specify the following options to define the owner of the file, overriding the default:
OWNER_MEMBER
OWNER_GROUP
These options specify the member number and group number of the owner of the file. Specify values for these options using fixed binary expressions. For example:
ENVIRONMENT (OWNER_GROUP (240), OWNER_MEMBER (5))
This example defines the owner of the file as any process that has the UIC [360,5]. Note that although the value can be specified to PL/I in decimal radix, the OpenVMS system always displays and interprets UICs in octal radix.
To specify an owner UIC for a file that is different from the UIC under which the current program is executing, the process must have the SYSPRV user privilege or a system UIC.
7.3.1.2. Defining a File's Protection
When you specify ENVIRONMENT options for a file you are creating in a PL/I program, you can specify the following options to define the access permitted to various users:
OWNER_PROTECTION
GROUP_PROTECTION
SYSTEM_PROTECTION
WORLD_PROTECTION
These options specify the types of access permitted by the specification of the following codes:
R-gives the right to read the file.
W-gives the right to modify the file.
E-for files containing executable program images, gives the right to execute the program.
D-gives the right to delete the file.
These codes can be specified in any order for an option; if you specify an option and omit a code, that category of user is denied that type of access. If you specify one or more protection options, the protection for unspecified categories defaults to no access. If you do not specify any protection options, then PL/I uses the current default protection for all the categories.
For example:
ENVIRONMENT (OWNER_PROTECTION ('RWE') SYSTEM_PROTECTION ('R') GROUP_PROTECTION('R'))
This specification defines protection to a file as follows:
The OWNER_PROTECTION option specifies RWE, that is, read, write, and execute access. Because D is not specified, the owner is not allowed delete access and thus cannot inadvertently delete the file.
The SYSTEM_PROTECTION and GROUP_PROTECTION options specify only read access for system and group users.
The WORLD_PROTECTION option is not specified; this denies all access to all users who are in the world category.
Note that the DCL command SET PROTECTION allows the owner of a file to change the file's protection at any time. Additional commands and user privileges allow the protection of a file to be overridden or changed. For details on these commands and privileges, see the OpenVMS DCL Dictionary.
The file system applies the protection you specify for a file when the file is accessed from a program or from the DCL command level. It also applies the protection when the file is to be shared.
7.3.2. File Sharing
RMS allows multiple programs to access records in the same file concurrently. The type of access is controlled by ENVIRONMENT specifications and by the current status of the file, that is, whether the file is open and, if it is open, whether it is open for input, output, or update.
The rules for sharing are as follows:
Sharing is valid only for disk files.
Sequential, relative, and indexed files can be read-shared; that is, any number of programs can read records in these files at the same time.
Relative and indexed sequential files can be write-shared; that is, any number of programs can read and write records in these files at the same time.
Sequential disk files can be write-shared only if there is a single program writing them at a time. Only one program can be writing a sequential file while other programs are reading it.
When you write a PL/I program or programs that will be sharing a file, you can specify the type of sharing. During execution of programs that share a file, RMS ensures the following:
If a file is already opened when another program attempts to open it, the file is available for sharing.
Only one program is writing a record at one time.
7.3.2.1. Specifying File Sharing
In a PL/I program, you can specify one of the following file-sharing options in the ENVIRONMENT attribute:
NO_SHARE
SHARED_READ
SHARED_WRITE
These options indicate the type of shared operations that can be performed on the file. The defaults for these options depend on the OPEN attributes, as follows:
| OPEN Attribute | Default Sharing |
|---|---|
| INPUT | SHARED_READ |
| OUTPUT | NO_SHARE |
| UPDATE | NO_SHARE |
You override these defaults by specifying options for ENVIRONMENT. For example, if SHARED_READ is specified on an OPEN statement for a file opened for UPDATE, the process that opened the file is the only legal writer of the file. Other processes can access the file only for reading; they must specify SHARED_WRITE to indicate that they allow writing of the file while they are reading it.
If SHARED_WRITE is specified, processes that subsequently access the file with the SHARED_WRITE option can write the file. Both the SHARED_READ and SHARED_WRITE options can be specified for a file.
Table 7.3, “Effects of File-Sharing Options” summarizes the effects of opening a file with file-sharing options.
| Open Option and Access Specified by First Opener | Open Option Specified by a Subsequent Opener | Access Allowed Subsequent Opener |
|---|---|---|
|
ENV(NO_SHARE)[a] INPUT, OUTPUT, or UPDATE |
ENV(NO_SHARE) ENV(SHARED_READ) ENV(SHARED_WRITE) | None. The UNDEFINEDFILE condition is signaled.[b] |
|
ENV(SHARED_READ) INPUT | ENV(NO_SHARE) | None. The UNDEFINEDFILE condition is signaled.[b] |
| ENV(SHARED_READ) | The file is accessed for input. | |
| ENV(SHARED_WRITE) | The UNDEFINEDFILE condition is signaled.[b] | |
|
ENV(SHARED_READ) OUTPUT or UPDATE | ENV(NO_SHARE) | None. The UNDEFINEDFILE condition is signaled.[b] |
| ENV(SHARED_READ) | None. The UNDEFINEDFILE condition is signaled.[b] | |
| ENV(SHARED_WRITE) | The file can be accessed for input only. | |
|
ENV(SHARED_WRITE) INPUT | ENV(NO_SHARE) | The UNDEFINEDFILE condition is signaled.[b] |
| ENV(SHARED_READ) | The file can be accessed for input, output, or update. | |
| ENV(SHARED_WRITE) | The file can be accessed for input, output, or update. | |
|
ENV(SHARED_WRITE) OUTPUT or UPDATE | ENV(NO_SHARE) | None. The UNDEFINEDFILE condition is signaled.[b] |
| ENV(SHARED_READ) | None. The UNDEFINEDFILE condition is signaled.[b] | |
| ENV(SHARED_WRITE) | The file can be accessed for input, output, or update. |
7.3.2.2. File Locking
If a file is first opened by a process in a manner that restricts sharing by other processes, RMS locks the file to prohibit access by other processes. If a PL/I procedure attempts to open a file already opened by another process for a type of access not allowed, the UNDEFINEDFILE condition is signaled. In an ON-unit that is executed for this condition, the ONCODE built-in function returns the value associated with the RMS status code RMS$_FLK (meaning that the file is locked).
In an application where files must be shared and the synchronization of sharing is important, a procedure can test whether a file is currently being accessed by another process and act accordingly. The following example illustrates an ON-unit that tests whether a file is locked:
ON UNDEFINEDFILE(STATE_FILE) BEGIN; %INCLUDE $RMSDEF; IF ONCODE() = RMS$_FLK THEN CALL WAITSYNC; ELSE CALL RESIGNAL(); END;
This ON-unit declares the symbolic name RMS$_FLK from PLI$STARLET.TLB and uses an IF statement to verify whether the error occurred because the file is currently locked. If so, the ON-unit calls the procedure WAITSYNC, which presumably synchronizes the procedure's execution. Otherwise, it calls the RESIGNAL built-in subroutine, to request that the default PL/I ON-unit handle the UNDEFINEDFILE condition.
7.3.2.3. Record Locking
When more than one process is accessing a file at the same time, it is necessary to ensure that no process can access a record while another process is writing, rewriting, or deleting the record. To protect access to records in a shared file, PL/I use the automatic record-locking capability of RMS. Manual record locking is also available, through the record-locking options of the READ statement (LOCK_ON_READ, LOCK_ON_WRITE, MANUAL_UNLOCKING, NOLOCK, NONEXISTENT_RECORD, READ_REGARDLESS, TIMEOUT_PERIOD, and WAIT_FOR_RECORD). These manual record-locking options are valid for all file organizations.
RMS-controlled record locking in PL/I occurs, for example, when one PL/I procedure executes a READ statement (without any record-locking options specified) for a record in a file opened with the UPDATE attribute. During the execution of the READ statement, RMS automatically keeps the record locked, and no other processes can access the record until it is freed.
A record is locked when both of the following are true:
A READ statement is issued for the record (without any record-locking options specified).
The file containing the record was opened with the OUTPUT or UPDATE attribute.
A record can also be locked by any of the following options on the READ statement:
LOCK_ON_READ
LOCK_ON_WRITE
MANUAL_UNLOCKING
NONEXISTENT_RECORD
READ_REGARDLESS (on a record that is not already locked)
A record remains locked until one of the following occurs:
The locked record is rewritten or deleted.
A READ, WRITE, REWRITE, or DELETE statement is executed to access another record in the same file.
The REWIND built-in subroutine is called to rewind the file to its beginning.
The FREE built-in subroutine is called to free all locked records in the file.
The RELEASE built-in subroutine is called to unlock the record.
The file is closed.
Records are also locked for the duration of a WRITE, REWRITE, or DELETE statement to ensure that the I/O is completed. The records are unlocked when these statements are completed.
If a procedure in another process attempts to access a record that is locked, the ERROR condition is signaled. In an ON-unit that is executed once this condition exists, a reference to the ONCODE built-in function returns the value associated with the RMS status code RMS$_RLK (meaning that the record is locked).
Thus, a file-sharing application can test whether a record in a file is currently locked in an ON-unit, as in the following example:
ON ERROR BEGIN; %INCLUDE $RMSDEF; IF ONCODE() = RMS$_RLK THEN CALL RECORDSYNC(); ELSE CALL RESIGNAL(); END;
The ON-unit in this example tests whether any ERROR condition is signaled as a result of an attempt to access a locked record. If so, the ON-unit calls a procedure that will synchronize with the other process reading the record. Otherwise, it calls the RESIGNAL built-in subroutine to perform default condition handling.
7.3.2.4. Examples of File Sharing
The following examples illustrate some of the principles of file sharing in PL/I. The procedure UPDATE_FILE obtains, modifies, and rewrites a record in a keyed file. It opens the file with the UPDATE attribute and with the ENVIRONMENT option SHARED_READ. It contains these statements:
UPDATE_FILE: PROCEDURE OPTIONS(MAIN); OPEN FILE(PARTS) RECORD UPDATE KEYED ENV( SHARED_READ); ⋮ READ FILE(PARTS) INTO(PARTLIST) KEY(INPUT_NUM); ⋮ REWRITE FILE(PARTS) FROM(PARTLIST);
The procedure PRINT_DATA reads the records in a keyed file sequentially, and displays certain fields in each record. It contains these statements:
PRINT_DATA: PROCEDURE OPTIONS(MAIN); OPEN FILE(PARTS) RECORD INPUT SEQUENTIAL ENV( SHARED_WRITE); ⋮ READ FILE(PARTS) INTO(PARTLIST); DO WHILE (^EOF); PUT SKIP LIST(PARTLIST.NAME,QUANTITY.IN_STOCK); READ FILE(PARTS) INTO(PARTLIST); END;
The procedure VIEW_DATA reads the records in a keyed file sequentially, and displays certain fields in each record. It does not modify any of the records; it only needs to read them, so it uses the READ statement options READ_REGARDLESS and NOLOCK. It contains these statements:
VIEW_DATA: PROCEDURE OPTIONS(MAIN); OPEN FILE(PARTS) RECORD INPUT SEQUENTIAL ENV( SHARED_WRITE); ⋮ READ FILE(PARTS) INTO(PARTLIST) OPTIONS(READ_REGARDLESS,NOLOCK); DO WHILE (^EOF); PUT SKIP LIST(PARTLIST.NAME,QUANTITY.IN_STOCK); READ FILE(PARTS) INTO(PARTLIST) OPTIONS(READ_REGARDLESS,NOLOCK); END;
For the purposes of these three examples, assume that the file PARTS is equated to the same OpenVMS file by logical name assignments so that each procedure is attempting access to the same file.
If the process running the program UPDATE_FILE is the first process to open the file, the file is opened for read sharing. When PRINT_DATA or VIEW_DATA opens the file with the SHARED_WRITE option, the file's attribute list indicates that other processes may be writing the file.
If these procedures are executing concurrently, and if, for example, UPDATE_FILE is processing a record in the file PARTS while PRINT_DATA is reading the file, it may happen that PRINT_DATA attempts access to the record being processed by UPDATE_FILE. In this case, the ERROR condition is signaled with the status code RMS$_RLK. But if VIEW_DATA attempts to read a record that is locked by UPDATE_FILE or PRINT_DATA, it can still access the record, because the READ_REGARDLESS option was specified. If VIEW_DATA is reading a record, the other two processes can still access the record, because NOLOCK was also specified as an option to the READ statement.
7.4. ENVIRONMENT Options for I/O Optimization
Many of the PL/I options for the ENVIRONMENT attribute provide optimization features for I/O operations. Table 7.4, “ENVIRONMENT Options for Optimized Disk File Creation” summarizes the options that control disk file allocation. These options let you specify the space requirements of a file when you create it. Table 7.5, “ENVIRONMENT Options for Run-Time Optimization of Input/Output” summarizes the options for run-time optimization of I/O processing.