12.5 INQUIRE Statement

The INQUIRE statement returns information on the status of specified properties of a file or logical unit. It takes one of the following forms:

Inquiring by File:

INQUIRE (FILE=name [, ERR=label] [, IOSTAT=i-var] [, DEFAULTFILE=def], slist)

Inquiring by Unit:

INQUIRE ([UNIT=]io-unit [, ERR=label] [, IOSTAT=i-var], slist)

Inquiring by Output List:

INQUIRE (IOLENGTH=len) out-item-list

Is a scalar default character expression specifying the name of the file for inquiry.

Is the label of the branch target statement that receives control if an error occurs.

Is a scalar integer variable that is defined as a positive integer if an error occurs and zero if no error occurs.

Is one or more inquiry specifiers. Each specifier can appear only once. (The inquiry specifiers are described individually in the following sections.)

Is a scalar default character expression specifying a default file name specification string. (For more information on the DEFAULTFILE specifier, see Section 12.6.10.)

Is an external unit specifier.

The unit does not have to exist, nor does it need to be connected to a file. If the unit is connected to a file, the inquiry encompasses both the connection and the file.

Is a scalar integer variable that is assigned a value corresponding to the length of an unformatted, direct-access record resulting from the use of the out-item-list in a WRITE statement.

The value is suitable to use as a RECL specifier value in an OPEN statement that connects a file for unformatted, direct access.

The unit of the value is 4-byte longwords, by default. However, if you specify the compiler option /ASSUME=BYTERECL, the unit is bytes.

Is a list of one or more output items (see Section 10.2.2).

Rules and Behavior

The control specifiers ([UNIT=]io-unit, ERR=label, and IOSTAT=i-var) and inquiry specifiers can appear anywhere within the parentheses following INQUIRE. However, if the UNIT specifier is omitted, the io-unit must appear first in the list.

An INQUIRE statement can be executed before, during, or after a file is connected to a unit. The specifier values returned are those that are current when the INQUIRE statement executes.

To get file characteristics, specify the INQUIRE statement after opening the file.


The following are examples of INQUIRE statements:


In the last statement, you can use the length returned in LEN as the value for the RECL specifier in an OPEN statement that connects a file for unformatted direct access. If you have already specified a value for RECL, you can check LEN to verify that A and B are less than or equal to the record length you specified.

For More Information:

Previous Page Next Page Table of Contents