Chapter 5
Options of the ENVIRONMENT Attribute
The options of the ENVIRONMENT attribute provided by Endless PL/I for POSIX Systems let you do the following:
Describe the attributes of a file when it is created or opened.
Request special processing and optimization options when the file is being read or written.
Specify the disposition of a file when it is closed.
This chapter presents an overview of the environment options and information on how to specify them, and gives a description of each option. The descriptions of the environment options are arranged in alphabetic order. The chapter concludes with a discussion of the environment options designed for file protection, file sharing, and I/O optimization.
5.1. Specifying and Using Environment Options
All environment options can be specified in the declaration of a file constant or, in the dec and ansi dialects, in an OPEN statement . Certain options can also be specified in a CLOSE statement.
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.
5.1.1. Arguments for Environment Options
Environment options fall into the following categories, based on whether they require an argument and, if so, what type of argument is 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 to enable or disable 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.
5.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(31).
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.
5.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.
5.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.
5.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, they determine the option for the file if the OPEN option creates the file. Because the options are not stored with the file, they must be given for each opening of a file. The results are unpredictable if the options given do not match with those existing for the file.
5.1.3. 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 MAXIMUM_RECORD_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.
5.2. Summary of ENVIRONMENT Options
The options to the PL/I ENVIRONMENT attribute for the DEC and ANSI dialects are summarized in alphabetic order in Table 5.2, “Summary of DEC and ANSI Dialect ENVIRONMENT Options”, and the ENVIRONMENT options for the IBM dialect in Table 5.3, “Summary of IBM Dialect ENVIRONMENT Options”. Table 5.1, “Description of Columns in Table 5.2, “Summary of DEC and ANSI Dialect ENVIRONMENT Options”” describes the columns in Table 5.2, “Summary of DEC and ANSI Dialect ENVIRONMENT Options”.
The sections following these tables describe the Endless PL/I for POSIX Systems environment options in detail.
| Option | Gives the name of the ENVIRONMENT option and its argument, if any. An option that does not show an argument can be specified with a Boolean argument. |
| Usage | Briefly describes the option. |
| Specify At | Indicates when the option is meaningful. The possible items in this column are: Create—the option can be specified on a DECLARE or OPEN. It is meaningful 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. |
| Option | 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) |
| DEFAULT_ FILE_NAME (expression) | Defines a default specification for a file. | Create Open | Record Stream | None | CHAR(128) VARYING |
| DELETE | Specifies that the file be deleted when it is closed. | Create Open Close | Record Stream | Disabled | BIT(1) |
| FILE_ID (variable) | Identifies a file by its internal file identification. | Open | Record Stream | Not applicable | (6)FIXED BINARY(31) |
| FILE_ID_TO (variable) | Identifies a file by its internal file identification. | Create Open | Record Stream | Not applicable | (6)FIXED BINARY(31) |
| 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 [a] | CHAR(4) |
| MAXIMUM_ RECORD_SIZE (expression) | Specifies the maximum size valid for records in the file. | Create | Record | Varies[b] | FIXED BINARY(31) |
| OWNER_ PROTECTION (expression) | Specifies the type of file access allowed the owner of the file. | Create | Record Stream | Current process default[a] | CHAR(4) VARYING |
| RECORD_ID_ ACCESS | Indicates that records will be accessed by internal file system identification. | Create Open | Record | Disabled | BIT(1) |
| SHARED_READ | Lets other users read records in the file. | Create Open | Record | Enabled[c] | BIT(1) |
| TEMPORARY | Specifies a temporary file which is deleted when the process terminates. | Create | Record Stream | Disabled | BIT(1) |
| WORLD_ PROTECTION (expression) | Specifies the type of file access allowed to general system users. | Create | Record Stream | Current process default ??? | CHAR(4) VARYING |
[a] See umask(1) [b] 512 bytes 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. [c] Enabled if the file is opened for input, otherwise disabled. | |||||
| Option | Usage | Specify At | Valid I/O Types | Default Value | Data Type |
|---|---|---|---|---|---|
| BLKSIZE (expression) | Specifies the size of a block when writing to a buffered file. | Create | Record | Current record size | FIXED BINARY(31) |
| CONSECUTIVE | Specifies that records in the file are placed in physical sequence. | Create | Record Stream | Enabled | BIT(1) |
| F|FB|FS|FBS | Specifies a file with fixed-length records of a maximum record size. These are all equivalent to F; the B and S portions are ignored. | Create | Record | Disabled | BIT(1) |
| RECSIZE | Specifies the maximum size valid for records in the file. | Create | Record Stream | Varies[a] | FIXED BINARY(31) |
| SCALARVARYING | Specifies that varying character strings are read/written using the entire storage of the variable. | Create | Record | Disabled | BIT(1) |
| V|VB|VS|VBS | Specifies a file with variable-length records with a maximum record size. These are all equivalent to V; the B and S portions are ignored. | Create | Record | Enabled | BIT(1) |
[a] 512 bytes 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. | |||||
Some environment options are accepted but ignored by the Endless PL/I for POSIX Systems compiler, for compatibility with other implementations of PL/I. Table 5.4, “ENVIRONMENT Options That Are Ignored” lists these options:
| Option | Usage | Specify At | Valid I/O Types | Default Value | Data Type |
|---|---|---|---|---|---|
| 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 |
| BLOCK_ BOUNDARY_ FORMAT | Indicates that records must not cross block boundaries. | Create | Record Stream | 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(31) |
| 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(31) |
| 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 |
| DEFERRED_ WRITE | Requests file system optimization of output. | Create Open | Record | 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(31) |
| FILE_SIZE (expression) | Defines the initial number of blocks to be allocated for a file. | Create | Record Stream | Not applicable | FIXED BINARY(31) |
| INDEX_NUMBER (expression) | Specifies the initial index to use in accessing records in an indexed sequential file. | CreateOpen | Record | Disabled | FIXED BINARY(31) |
| INDEXED | Defines an indexed sequential file. | Open | Record | Disabled | BIT(1) |
| INITIAL_FILL | Specifies that the initial fill value specified when the file was created is to be used. | Open | Record | Enabled | 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(31) |
| MULTIBLOCK_ COUNT (expression) | Specifies the number of blocks to be allocated for file system buffering. | Create Open | Record | Current process default | FIXED BINARY(31) |
| MULTIBUFFER_ COUNT (expression) | Specifies the number of buffers to be allocated for file system buffering. | Create Open | Record | Current process default | FIXED BINARY(31) |
| NO_SHARE | Prohibits all types of shared access to the file. | Open |
Record ISAM only | Enabled | 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) |
| 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(31) |
| REVISION_DATE (variable) | Overrides the default revision date of the file. | Close | Record Stream | Date and time file is closed | BIT(64) ALIGNED |
| SHARED_WRITE | ALLOWS OTHER USERS TO READ AND WRITE RECORDS IN THE FILE. | create open |
Record ISAM only | Disabled | BIT(1) |
| SUPERSEDE | Replaces an existing file with the same file name, file type, and version number. | Create | Record Stream | Enabled | 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) |
| TRUNCATE | Specifies that any unused space allocated for a file be deallocated when the file is closed | Create Open Close | Record | Enabled | Bit(1) |
| 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) |
Valid Dialects: ansi, dec
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 or overwrite an existing file.
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.
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, you can open the file as follows:
DECLARE LISTFILE FILE SEQUENTIAL OUTPUT; ⋮ OPEN FILE(LISTFILE) ENVIRONMENT(APPEND);
This OPEN statement opens the file LISTFILE. The file is positioned at its current end-of-file.
Valid Dialects: ibm
The BLKSIZE option sets the size of a buffer in BUFFERED file. This option is valid only with BUFFERED files and is ignored otherwise. The format of this option is:
BLKSIZE(size)size
A positive integer or a fixed binary(31) static variable specifying the maximum block size for the file. Valid values range from the current record size to 32767 bytes. Note that the actual length of a variable-length record includes the four control bytes containing length information.
Although PL/I provides a default of the current record size, this default will not give you any of the advantages of buffered I/O. To improve performance when using buffers to write to a file, specify a block-size that is a multiple of the record size plus any control bytes.
Valid Dialects: ibm
The CONSECUTIVE option specifies that records in a file are placed in physical sequence. Once the location of one record is determined, the next record location can be determined by its physical position in the file.
CONSECUTIVE [ (boolean-expression) ]Rules
The CONSECUTIVE option is valid when a file is created.
Usage
The CONSECUTIVE option is enabled by default; you need not specify it explicitly.
Valid Dialects: ansi, dec
The DEFAULT_FILE_NAME option specifies default file name for a file. Its format is:
DEFAULT_FILE_NAME [ (character-expression) ]character-expressionIs a character-string expression.
Rules
The DEFAULT_FILE_NAME option is meaningful when a file is created or opened.
The
character-expressionmay optionally containing an asterisk (*). If there is no asterisk in the character expression, an asterisk is assumed to be at the rightmost end. The maximum length of the string is 128 characters.The value of the TITLE option is inserted in the position of the (assumed) asterisk.
The next example shows how to open the file /usr/users/tim/employee.dat:
OPEN FILE (INFILE) INPUT TITLE('employee') ENVIRONMENT(DEFAULT_FILE_NAME('/usr/users/tim/*.dat'));
The following example shows how to open the file /tmp/workfile:
OPEN FILE (INFILE) INPUT TITLE('workfile') ENVIRONMENT(DEFAULT_FILE_NAME('/tmp/'));
Valid Dialects: ansi, dec
The DELETE option specifies that the file is to be deleted when it is closed. The format of this option is:
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.
The DELETE option can not be used on an indexed sequential file.
Usage
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 file associated with the PL/I file constant INFILE is deleted.
Valid Dialects: ibm
The F, FB, FS, and FSB options all equate to the dec/ansi dialect FIXED_LENGTH_RECORDS option. Blocking and spanning are unsupported. The format of this option is:
F [ (boolean-expression) ]See Section 5.11, “FIXED_LENGTH_RECORDS Option” for more information.
5.9. FILE_ID Option
Valid Dialects: ansi, dec
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:
FILE_ID(variable-reference)variable-referenceSpecifies the name of the 6-element array variable containing the file identification. See Section 5.10, “FILE_ID_TO Option” for information on obtaining the file identification when you create a file.
The variable must be declared as (6) FIXED BINARY(31) 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.
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.
5.10. FILE_ID_TO Option
Valid Dialects: ansi, dec
Use the FILE_ID_TO option to obtain the file identification when you create a file. Its format is:
FILE_ID_TO(variable-reference)variable-referenceSpecifies the name of the 6-element array variable. PL/I returns the file identification of the created file to this variable.
You must declare the variable as (6) FIXED BINARY(31), and it must be connected.
Rules
The FILE_ID_TO option is meaningful when a file is created or opened.
FILE_ID_TO option conflicts with the FILE_ID option.
This option can only be used 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.
Valid Dialects: ansi, dec
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:
FIXED_LENGTH_RECORDS [ (boolean-expression) ]Rules
The FIXED_LENGTH_RECORDS option must be specified at both creation and open time.
The FIXED_LENGTH_RECORDS option conflicts 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 512 bytes for stream files and a default length of 480 bytes for relative files. There is no default for indexed files.
Valid Dialects: ansi, dec
The GROUP_PROTECTION option defines the type of access to be permitted to the file by other users in the owner's group (also see id(1)). The format of this option is:
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:
r—Read access is allowed.
w—Write/delete access is allowed.
x—Execute access is allowed.
Letters can be repeated, but the maximum length of the string is 4 characters. The
character-expressionstring is case insensitive; "W" and "w" are equivalent.For compatibility with OpenVMS implementations of PL/I, you can use "d" as a synonym for "w", and "e" as a synonym for "x". 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 applies the current system or process default protection (see umask(1)). If any protection options are specified, the protection for unspecified user categories defaults to no access.
Valid Dialects: ansi, dec
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.
The format of this option is:
MAXIMUM_RECORD_SIZE(integer-expression)integer-expressionIs a numeric expression with values in the range 1 to 32,767. 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 when a file is created and when it is opened. If the specified opened size does not match the specified created size, the results are undefined. 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 |
Valid Dialects: ansi, dec
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 (UID). Refer to id(2) for more information. The format of this option is:
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. The character-string expression can contain any of the following letters to indicate the access allowed:
r—Read access is allowed.
w—Write/delete access is allowed.
x—Execute access is allowed.
Letters can be repeated, but the maximum length of the string is 4 characters. The
character-expressionstring is case insensitive; "W" and "w" are equivalent.For compatibility with OpenVMS implementations of PL/I, you can use "d" as a synonym for "w", and "e" as a synonym for "x". 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 (see umask(1)). If any protection options are specified, the protection for unspecified user categories defaults to no access.
5.15. RECORD_ID_ACCESS Option
Valid Dialects: ansi, dec
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:
RECORD_ID_ACCESS [ (boolean-expression) ]Rules
The RECORD_ID_ACCESS option is meaningful when a file is created or opened.
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. See Chapter 6, Input/Output Statement Options for more information.
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.
Valid Dialect: ibm
The RECSIZE 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 a stream file, the RECSIZE option is the same as specifying a LINESIZE on the OPEN statement. Note that specification of LINESIZE on the OPEN statement overrides a prior specification of RECSIZE on the declaration.
The format of this option is:
RECSIZE(integer-expression)integer-expressionIs a numeric expression with values in the range 1 to 32,767. 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
If RECSIZE is 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 |
5.17. SCALARVARYING Option
Valid Dialects: ansi, dec, ibm
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.
5.19. SUPERSEDE Option
Valid Dialects: ansi, dec
The SUPERSEDE option specifies that if a file already exists with the same name and type, it will be deleted and a new file created in its place. This is the default. The format of this option is:
SUPERSEDE [ (boolean-expression) ]Rules
The SUPERSEDE option is meaningful only when a file is created.
The SUPERSEDE option conflicts with the APPEND option.
Compatibility Note
On VAX VMS, the default is not to supersede.
Usage
By default, the file system creates a new file whenever a file is opened for output.
5.20. TEMPORARY Option
Valid Dialects: ansi, dec
The TEMPORARY option creates a temporary file name using tempnam(3s). The format of this option is:
TEMPORARY [ (boolean-expression) ]Rules
The TEMPORARY option is meaningful only when a file is created.
The TEMPORARY option conflicts with the TITLE and the DEFAULT_FILE_NAME options.
Usage
When you create a file with the TEMPORARY option, the file system calls tempnam(3s) to create a uniquely named temporary file. A file thus created can be used during the execution of the program and deleted on completion, without cluttering up the current working directory.
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 the name of the temporary file is not available to a PL/I application, 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(31); 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.
Valid Dialects: ibm
The V, VB, VS, and VSB options all equate to the variable length record format, which is the default record format for all dialects. Blocking and spanning are unsupported.
V [ (boolean-expression) ]Rules
The V option is valid when a file is created.
Usage
The variable record format is enabled by default; you need not specify it explicitly.
Valid Dialects: ansi, dec
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 are not the superuser. Refer to id(1). The format of this option is:
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:
r—Read access is allowed.
w—Write/delete access is allowed.
x—Execute access is allowed.
Letters can be repeated, but the maximum length of the string is 4 characters. The
character-expressionstring is case insensitive; "W" and "w" are equivalent.For compatibility with OpenVMS implementations of PL/I, you can use "d" as a synonym for "w", and "e" as a synonym for "x". 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 applies the current system or process default protection (see umask(1)). If any protection options are specified, the protection for unspecified user categories defaults to no access.
5.23. ENVIRONMENT Options for File Protection and File Sharing
This section discusses the ENVIRONMENT options that take advantage of special processing options for file protection and file sharing.
5.23.1. File Protection
Each user who is authorized to use the system is assigned a user identification (UID) and a group id (GID) by the system manager. When a PL/I program creates a file, the current UID associated with the process executing the program defines the file's ownership.
Based on this UID, called the owner UID, the file system defines the file protection in terms of which users on the system can access the file and what operations they can perform on the file. These users are defined as follows:
Owner—Any other process that has the same UID as the file's owner is also the owner of a file.
Group—A process that has the same GID is a member of the owner's group.
World—All processes that do not fall into the other categories belong to the world category.
The types of permissions defined for a file are:
Read access—the right or permission to perform an input operation
Write access—the right or permission to perform an output, update, or delete operation
Execute access—the right or permission to execute an executable file
The types of permissions defined for a directory are:
Read access—the right or permission to read the directory and see information about the files it contains
Write access—the right or permission to create or delete files in the directory
Execute access—the right or permission to see information about files you know about
The difference between read access and execute access is that you are allowed to perform wildcard operations on a directory you have read access to, but you must know the exact pathname of a file in a directory to which you have only execute access.
You can explicitly control the protection applied to a file by specifying the type of access allowed each category of user.
In a PL/I program, you can specify file protection when you create the file.
5.23.2. Defining File 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
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 (or d)—gives the right to modify or delete the file.
x (or e)—gives the right to execute executable files.
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 (umask) for all the categories.
For example:
ENVIRONMENT ( OWNER_PROTECTION ('rwx') GROUP_PROTECTION('w')) WORLD_PROTECTION ('r')
This specification defines protection to a file as follows:
The OWNER_PROTECTION option specifies rwx, that is, read, write, delete and execute access. This gives the owner permission to do anything to the file.
The GROUP_PROTECTION option specifies only write access for group users.
The WORLD_PROTECTION option specifies only read access.
Note that the UNIX command chmod lets the owner of a file change file permissions at any time. Additional commands and user privileges let users override or change file permissions. For details on these commands and privileges, see umask(1).
The file system applies the permissions you specify for a file when the file is accessed from a program or from the command level. It also applies the permissions when the file is shared.
5.24. File Sharing
PL/I lets multiple programs access records in the same file concurrently. All files are opened for SHARED_READ and access is controlled by the UNIX-level permissions on the file. Any number of programs can read records in a PL/I file providing they have access to the file.