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

Chapter 8

Input/Output Statement Options

PL/I permits the specification of the OPTIONS keyword on I/O statements and supports certain options for each statement. This chapter explains how to code options for I/O statements, lists the valid options for each I/O statement, and describes each option individually.

An I/O statement option remains in effect only for the duration of the statement on which it is specified. The only exception to this rule is the INDEX_NUMBER option.

8.1. Option Format

I/O statement options are specified in a statement by the OPTIONS keyword and an options list. You enclose the options list in parentheses, and separate individual options by commas, as follows:

OPTIONS (option,... ;

Following is an example of the I/O statement GET with three options, PROMPT, NO_ECHO, and PURGE_TYPE_AHEAD:

GET LIST (PASSWORD) OPTIONS (PROMPT('Enter password: '),
                             NO_ECHO,
                             PURGE_TYPE_AHEAD);

Any option that does not require an argument can be followed by a Boolean expression in the following format:

option(Boolean-expression)

where Boolean-expression is a bit string of length 1,'1'B for true or '0'B for false. If no Boolean expression is specified and the option is present in the option list, the default value of true is supplied.

8.2. Summary of Input/Output Statement Options

Table 8.1, “Summary of Input/Output Statement Options” lists the I/O options, briefly describes their uses, indicates which statements they are valid for, and gives their data types.

Table 8.1. Summary of Input/Output Statement Options
OptionUsageValid StatementsData Type
CANCEL_CONTROL_ODisables effect of Ctrl/o prior to terminal output.PUTBIT(1)
FAST_DELETEDeletes a record without updating alternate indexes.DELETEBIT(1)
FIXED_CONTROL_FROM (variable)Modifies the fixed control area of a record.

REWRITE

WRITE

Data type of fixed control area
FIXED_CONTROL_TO (variable)Returns the contents of the fixed control areaREADData type of fixed control area
INDEX_NUMBER (expression)Specifies the index to which an I/O operation applies.

DELETE

READ

REWRITE

FIXED BINARY(31)
LOCK_ON_READLocks a record for reading and allows other readers but no writers.READBIT(1)
LOCK_ON_WRITELocks a record for writing and allows other readers but no writers.READBIT(1)
MANUAL_UNLOCKINGSpecifies that the user, not RMS, is to control record locking and unlocking.READBIT(1)
MATCH_GREATERMatches any key with a value greater than the value of the KEY option.

DELETE

READ

REWRITE

BIT(1)
MATCH_GREATER_EQUALMatches any key with a value greater than or equal to the value of the KEY option.

DELETE

READ

REWRITE

BIT(1)
MATCH_NEXTMatches any key with a value greater than the value of the KEY option.

DELETE

READ

REWRITE

BIT(1)
MATCH_NEXT_EQUALMatches any key with a value greater than or equal to the value of the KEY option.

DELETE

READ

REWRITE

BIT(1)
NO_ECHOSuppresses display of input data on a terminal.GETBIT(1)
NO_FILTERSuppresses recognition of Ctrl/u, Ctrl/r, and the DEL key on input operations.GETBIT(1)
NOLOCKDisables record locking for the current operation.READBIT(1)
NONEXISTENT_RECORDLocks a nonexistent record.READBIT(1)
PROMPT (expression)Writes a prompting message prior to an input operation.GETCHAR(*)
PURGE_TYPE_AHEADClears a terminal's type-ahead buffer before reading input data.GETBIT(1)
READ_REGARDLESSEnables a record to be read regardless of any lock.READBIT(1)
RECORD_ID (variable)Accesses a record based on its internal identification.

DELETE

READ

REWRITE

(2) FIXED BINARY(31)
RECORD_ID_TO (variable)Returns the value of a record's internal identification.

READ

REWRITE

WRITE

(2) FIXED BINARY(31)
TIMEOUT_PERIOD (expression)Avoids a potential deadlock by indicating the number of seconds to wait before returning an error; used only with WAIT_FOR_RECORD.READFIXED BINARY(31)
WAIT_FOR_RECORDIf a record is locked, causes the process to wait until it is available.READBIT(1)

8.2.1. CANCEL_CONTROL_O Option

The CANCEL_CONTROL_O option specifies, when the output device is a terminal, that the effect of Ctrl/o is disabled before data is output. This ensures that the beginning of the output list is displayed.

Rules

  • The CANCEL_CONTROL_O option is valid only on a PUT statement.

  • This option is ignored when the output device is any device other than an interactive terminal.

Usage

Use this option on a PUT statement that you want displayed regardless of whether previous output has been interrupted by Ctrl/o. By default, the Ctrl/o function remains in effect until another Ctrl/o. For example:

PUT SKIP LIST('Phase 1 complete... beginning phase 2...')
          OPTIONS (CANCEL_CONTROL_O);

If program output has been suspended by Ctrl/o prior to execution of the PUT statement, the CANCEL_CONTROL_O option on the PUT statement cancels the effect of the Ctrl/o and outputs the data list.

8.2.2. FAST_DELETE Option

The FAST_DELETE option specifies, for a record in an indexed sequential file with alternate indexes, that only the current index for the file is to be updated.

The alternate index or indexes for the deleted record are not updated until the next time access is attempted to the record through an alternate index.

Rules

  • The FAST_DELETE option is valid only on a DELETE statement.

  • This option applies only to indexed sequential files.

Usage

This option can improve the speed of deletions when an indexed sequential file is updated.

8.2.3. FIXED_CONTROL_FROM Option

The FIXED_CONTROL_FROM option specifies a value to be written in the fixed control portion of a record in a file with variable-length records and a fixed control area. The format of the option is as follows:

FIXED_CONTROL_FROM (variable-reference)
variable-reference

Specifies the variable associated with the fixed control area. The variable can be a scalar or a connected aggregate variable. It must not be an unaligned bit string or an aggregate consisting entirely of unaligned bit-string variables.

Rules

  • The FIXED_CONTROL_FROM option is valid on the WRITE and REWRITE statements.

  • The file must have variable-length records with a fixed-length control area and must be opened with the OUTPUT or UPDATE attribute. If the file is opened with the OUTPUT attribute, the ENVIRONMENT option FIXED_CONTROL_SIZE must also be specified.

  • The length of the variable must match the length of the fixed control area, as specified in the FIXED_CONTROL_SIZE option of ENVIRONMENT. If the variable is not of the correct length, the ERROR condition is signaled.

Usage

The following example illustrates writing a file with sequence numbers in a fixed control area:

DECLARE (OUTFILE,INFILE) FILE,
        LINE_NUM FIXED BINARY(15), /* sequence numbers */
        COPY_REC CHARACTER(132) VARYING,
        EOF BIT(1) STATIC INIT('0'B);
OPEN FILE(INFILE) INPUT SEQUENTIAL;
ON ENDFILE(INFILE) EOF = '1'B;
OPEN FILE (OUTFILE) OUTPUT RECORD SEQUENTIAL
         ENVIRONMENT (FIXED_CONTROL_SIZE(2));
READ FILE(INFILE) INTO(COPY_REC);

/* Increment sequence number; copy record to output file */
DO LINE_NUM = 100 BY 100 WHILE (^EOF);
       WRITE FILE(OUTFILE) FROM (COPY_REC)
            OPTIONS(FIXED_CONTROL_FROM (LINE_NUM));
       READ FILE(INFILE) INTO(COPY_REC);
       END;
CLOSE FILE (INFILE);
CLOSE FILE(OUTFILE) ENVIRONMENT (SPOOL);

In this example, the OpenVMS file associated with the PL/I file OUTFILE will have a 2-byte fixed control area. Line numbers are assigned in increments of 100. Note that a file in this format, that is, a file that has CARRIAGE_RETURN_FORMAT carriage control (the default) and a 2-byte fixed control area, is handled in a special way by the OpenVMS system. When this file is printed with the DCL command PRINT or queued by the SPOOL option (as in this example), the contents of the fixed control area are printed to the left of each record on the output listing.

8.2.4. FIXED_CONTROL_TO Option

The FIXED_CONTROL_TO option specifies that the contents of the fixed control area of a record in a file with a fixed control area are to be assigned to a specified variable. The format of the option is as follows:

FIXED_CONTROL_TO (variable-reference)
variable-reference

Specifies the variable associated with the fixed control area. The variable can be a scalar or a connected aggregate variable. It must not be an unaligned bit string or an aggregate consisting entirely of unaligned bit-string variables.

Rules

  • The FIXED_CONTROL_TO option is valid only on a READ statement.

  • The file must have variable-length records with a fixed-length control area and must be opened with the INPUT attribute and with the ENVIRONMENT option FIXED_CONTROL_SIZE_TO.

  • If the file is an existing file, the length of the variable must match the length of the fixed control area. If the length is not correct, the ERROR condition is signaled.

8.2.5. INDEX_NUMBER Option

The INDEX_NUMBER option specifies the particular index in an indexed sequential file to which a KEY option applies (primary index, secondary index, and so on). The format of this option is as follows:

INDEX_NUMBER (integer-expression)
integer-expression

Specifies the index to be used. The value of the integer expression must be the number of an index for records in an indexed sequential file. The primary index is 0, the secondary index is 1, and so on.

Rules

  • The INDEX_NUMBER option is valid on a READ, REWRITE, or DELETE statement.

  • The file must be an indexed sequential file, and the KEY option must also be specified on the statement.

Usage

The INDEX_NUMBER option on an I/O statement overrides the current index number, which can be set explicitly by the INDEX_NUMBER option of ENVIRONMENT or implicitly by a WRITE statement that specifies the KEY option or the RECORD_ID option.

When the INDEX_NUMBER option is used, the specified index becomes the current index for the file and is used in this and in all subsequent I/O operations until the INDEX_NUMBER option is again specified. For example:

GET LIST(BIRD) OPTIONS (PROMPT('Enter bird'));

READ FILE(STATEFILE) INTO(STATE) KEY(BIRD)
            OPTIONS (INDEX_NUMBER(2));

In this example, the READ statement accesses the record in the file STATEFILE using the index numbered 2.

8.2.6. LOCK_ON_READ Option

The LOCK_ON_READ option specifies a lock for reading that allows other readers but no writers. If you specify this option, then a record stream with a shared file that is open for reading only, is permitted to lock a record from modification by other programs or streams. Other streams are permitted to read the record but not to lock it.

Rules

  • The LOCK_ON_READ option is valid only on a READ statement.

  • This option conflicts with the NOLOCK option.

  • This option remains in effect only for the current statement; then it is reset to false.

8.2.7. LOCK_ON_WRITE Option

The LOCK_ON_WRITE option specifies that a record will be locked for possible modifications. However, readers will be able to access the record. Streams that are locking records for modification can therefore allow nonlocking streams to read locked records.

Rules

  • The LOCK_ON_WRITE option is valid only on a READ statement.

  • This option conflicts with the NOLOCK option.

  • This option remains in effect only for the current statement; then it is reset to false.

8.2.8. MANUAL_UNLOCKING Option

The MANUAL_UNLOCKING option specifies that a record will be locked until it is explicitly unlocked by the process, thus giving you (instead of RMS) control over locking and unlocking.

Rules

  • The MANUAL_UNLOCKING option is valid only on a READ statement.

  • This option conflicts with the NOLOCK option.

  • This option remains in effect only for the current statement; then it is reset to false.

8.2.9. MATCH_NEXT Option

The MATCH_NEXT option specifies that the record of interest is the first record whose key is greater than the key specified in the KEY option. MATCH_NEXT overrides the default rule for key matching, which is to look for an exact key match.

MATCH_GREATER is an obsolete synonym for MATCH_NEXT.

Rules

  • The MATCH_NEXT option is valid on the READ, REWRITE, and DELETE statements.

  • The KEY option must also be specified.

  • The file must be an indexed sequential file or a relative file.

  • The MATCH_NEXT option conflicts with the MATCH_NEXT_EQUAL option.

  • The MATCH_NEXT option remains in effect only for the current statement; then it is reset to false.

Usage

In the following example, STATE_FILE's third alternate key (that is, index number 3) is a fixed binary population value:

DECLARE 1 STATE,
          2 NAME CHARACTER(20),         /* Primary key */
          2 POPULATION FIXED BINARY(31),/* index #3 */
          2 CAPITAL,
           ⋮
        SIZE FIXED BINARY(31),
        STATE_FILE FILE RECORD INPUT KEYED SEQUENTIAL;
           ⋮
GET LIST(SIZE) OPTIONS(PROMPT(
       'Population value: '));
READ FILE(STATE_FILE) INTO(STATE) KEY(SIZE)
       OPTIONS(MATCH_NEXT,INDEX_NUMBER(3));

This READ statement obtains the record for the state whose population is greater than the value entered for the GET statement. For example, a value can be entered in response to this prompt as follows:

Population value: 8000000

In this case, the READ statement would read the first record in the index numbered 3 whose key value is greater than 8000000.

8.2.10. MATCH_NEXT_EQUAL Option

The MATCH_NEXT_EQUAL option specifies that the record of interest is the record whose key matches the key specified in the KEY option or, if no match is found, the first record whose key is greater than the key specified.

MATCH_GREATER_EQUAL is an obsolete synonym for MATCH_NEXT_EQUAL.

Rules

  • The MATCH_NEXT_EQUAL option is valid on the READ, REWRITE, and DELETE statements.

  • The KEY option must also be specified.

  • The file must be an indexed sequential file or a relative file.

  • The MATCH_NEXT_EQUAL option conflicts with the MATCH_NEXT option.

  • The MATCH_NEXT_EQUAL option remains in effect only for the current statement; then it is reset to false.

8.2.11. NO_ECHO Option

The NO_ECHO option specifies, when the input device is a terminal, that the data entered at the terminal will not be displayed as it is entered.

Rules

  • The NO_ECHO option is valid only on a GET statement.

  • This option is ignored if the input device is not a terminal.

  • This option remains in effect only for the current statement; then it is reset to false.

Usage

This option is useful when data entered at a terminal is to be protected from being seen by users other than the one who entered the data. For example, if a password is to be entered, the NO_ECHO option protects the password, as follows:

GET LIST (PASSWORD) OPTIONS (NO_ECHO,
                            PROMPT('Enter Password: '));

Data entered in response to this GET statement is not displayed on the terminal.

8.2.12. NO_FILTER Option

The NO_FILTER option specifies, when the input device is a terminal, that the recognition of Ctrl/u, Ctrl/r, and the DEL key is to be suppressed. These characters are interpreted as terminators.

Rules

  • The NO_FILTER option is valid only on a GET statement.

  • This option is ignored if the input device is not a terminal.

  • This option remains in effect only for the current statement; then it is reset to false.

Usage

When NO_FILTER is in effect, the terminal keys that normally permit a user to edit data as it is entered do not perform their normal functions. For example:

123DEL

If this data is entered in response to a GET statement that specifies the NO_FILTER option, the DEL key does not delete the last character typed (3); instead, it acts as the terminator of the input, just as the RETURN key usually does, and the value 123 is assigned to the input variable.

8.2.13. NOLOCK Option

The NOLOCK option specifies that a record accessed with a READ statement is not to be locked during the current operation.

Rules

  • The NOLOCK option is valid only on a READ statement.

  • This option should not be used if the record is to be updated or deleted, because an attempt to perform either one of these operations on an unlocked record will fail.

  • The NOLOCK option conflicts with the LOCK_ON_READ, LOCK_ON_WRITE, and MANUAL_UNLOCKING options.

  • The NOLOCK option remains in effect only for the current statement; then it is reset to false.

Usage

The NOLOCK option can improve the speed of reading if it is used on a file that is opened with the ENVIRONMENT option SHARED_READ or with both SHARED_READ and SHARED_WRITE.

8.2.14. NONEXISTENT_RECORD Option

The NONEXISTENT_RECORD option locks a randomly accessed record that does not exist in the file at the time of access. It prevents other streams from putting a new record into that cell until the stream that locked it either puts a record there itself or releases the record lock.

Rules

  • The NONEXISTENT_RECORD option is valid only on a READ statement.

  • This option applies only to relative files.

  • This option remains in effect only for the current statement; then it is reset to false.

8.2.15. PROMPT Option

When the input device is a terminal, the PROMPT option specifies a character-string prompt to be displayed prior to actual input. The format of this option is as follows:

PROMPT (string-expression)
string-expression

Specifies a 1- to 254-character string expression.

Rules

  • The PROMPT option is valid only on a GET statement.

  • This option is meaningful only when the input device is a terminal.

Usage

Unlike a PUT statement followed by a GET statement, a GET statement with the PROMPT option is actually executed as a single statement. For example:

GET LIST (NUM) OPTIONS (PROMPT('Enter number: '));

When this statement is executed, the terminal display would be as follows:

Enter number: 44Return

The prompting string and the input data occur in the same statement.

On a terminal, using the PROMPT option provides the following benefits:

  • If the display of the prompting string is interrupted, for example, by a broadcast message, the entire string is redisplayed following the message that interrupted it.

  • If Ctrl/u or Ctrl/r is entered in response to the prompt, the prompt message is repeated until data is entered.

The PROMPT option causes any data that was not processed by the last GET operation to be ignored. If the SKIP option is not specified, the prompt is output at the current cursor position. If you specify the SKIP option in conjunction with the PROMPT option, the SKIP operation is performed before the prompting message is displayed.

8.2.16. PURGE_TYPE_AHEAD Option

When the input device is a terminal, the PURGE_TYPE_AHEAD option specifies that all data in the terminal's type-ahead buffer be deleted before the input operation is performed.

Rules

  • The PURGE_TYPE_AHEAD option is valid only on a GET statement.

  • This option is ignored if the input device is not a terminal.

Usage

When a command or program is being executed, the terminal keyboard accepts input data and stores it in a buffer called the type-ahead buffer. When the command or program is completed, the command interpreter reads its next command from the type-ahead buffer. When a GET statement is executed with this option in effect, any data in the type-ahead buffer is deleted, ensuring that the GET statement will not read any extraneous data.

8.2.17. READ_REGARDLESS Option

The READ_REGARDLESS option allows a record to be read regardless of whether it is locked.

Rules

  • The READ_REGARDLESS option is valid only on a READ statement.

  • The READ_REGARDLESS option conflicts with the WAIT_FOR_RECORD option.

  • If the record is not already locked, the READ_REGARDLESS option locks it.

  • The READ_REGARDLESS option remains in effect only for the current statement; then it is reset to false.

8.2.18. RECORD_ID Option

The RECORD_ID option indicates that the record of interest is specified by its record identification. The format of this option is as follows:

RECORD_ID (variable-reference)
variable-reference

Specifies the name of a 2-element array variable containing the record identification.

The variable must be declared as (2) FIXED BINARY(31), and it must be a connected array.

Rules

  • The RECORD_ID option is valid on a READ, REWRITE, or DELETE statement.

  • RECORD_ID conflicts with the KEY option on the READ, REWRITE, or DELETE statement.

  • The file on which the operation is being performed must have been opened with the ENVIRONMENT option RECORD_ID_ACCESS.

  • If the file is an indexed sequential file, the RECORD_ID option resets the value of the current index number to 0.

Usage

The following example illustrates a record whose record identification is saved for later file access.

DECLARE
BOOKFILE FILE RECORD KEYED,
        INBUF CHARACTER(180) VARYING,
        SAVE_RECORD_ID(2) FIXED BINARY(31),
        KEYVALUE CHARACTER(10);
   ⋮
OPEN FILE(BOOKFILE) ENV(RECORD_ID_ACCESS);
READ FILE(BOOKFILE) INTO(INBUF) KEY(KEYVALUE)
          OPTIONS(RECORD_ID_TO(SAVE_RECORD_ID));
   ⋮
CLOSE FILE(BOOKFILE);
   ⋮
OPEN FILE(BOOKFILE) INPUT ENV(RECORD_ID_ACCESS);
READ FILE(BOOKFILE) INTO(INBUF) OPTIONS(
    RECORD_ID(SAVE_RECORD_ID));

During the first opening of the file, the record identification of a specified record is obtained and saved. When the file is subsequently reopened, this value is used to access a record and to effectively position the file at that record.

8.2.19. RECORD_ID_TO Option

The RECORD_ID_TO option specifies the name of a variable to be assigned the value of the record identification of the record on which the current operation is being performed. The format of this option is as follows:

RECORD_ID_TO (variable-reference)
variable-reference

Is a reference to a 2-element array variable that will receive the value of the record's identification.

The variable must be declared as (2) FIXED BINARY(31), and it must be connected.

Rules

  • The RECORD_ID_TO option is valid on the READ, WRITE, and REWRITE statements.

  • The file on which the operation is being performed must have been opened with the RECORD_ID_ACCESS option of the ENVIRONMENT attribute.

8.2.20. TIMEOUT_PERIOD Option

The TIMEOUT_PERIOD option, used only with the WAIT_FOR_RECORD option, causes the waiting condition to continue only for the specified timeout period, in seconds. If the timeout period expires before the lock is granted, an error is signaled.

Rules

  • The TIMEOUT_PERIOD option is valid only on a READ statement.

  • If the TIMEOUT_PERIOD option is specified without the WAIT_FOR_RECORD option, it is ignored.

  • The timeout period must be between 0 and 255 seconds.

  • The TIMEOUT_PERIOD option remains in effect while the WAIT_FOR_RECORD option remains in effect, that is, for the current statement only.

Usage

The TIMEOUT_PERIOD option prevents the WAIT_FOR_RECORD option from potentially causing an indefinite deadlock in the process.

In the following example, a 10-second waiting period is specified for a locked record. If the record is still locked after that period expires, an error is signaled.

READ FILE(DATAFILE) INTO (BUFFER)
   OPTIONS(WAIT_FOR_RECORD,TIMEOUT_PERIOD(10));

8.2.21. WAIT_FOR_RECORD Option

The WAIT_FOR_RECORD option specifies that if a record is already locked, the process will wait until the record is available.

Rules

  • The WAIT_FOR_RECORD option is valid only on a READ statement.

  • The WAIT_FOR_RECORD option conflicts with the READ_REGARDLESS option.

  • The WAIT_FOR_RECORD option remains in effect only for the current statement; then it is reset to false.

Usage

The WAIT_FOR_RECORD option can be used with the TIMEOUT_PERIOD option to avoid an indefinite wait.