Previous | Contents | Index |
IF | Executes a list of commands conditionally |
FOR | Executes a list of commands repetitively |
REPEAT | Executes a list of commands repetitively |
WHILE | Executes a list of commands conditionally |
EXITLOOP | Exits an enclosing WHILE, REPEAT, or FOR loop |
SET PROMPT | Specifies the debugger prompt |
SET OUTPUT [NO]TERMINAL | Controls whether debugger output is displayed or suppressed, except for diagnostic messages |
SET
SHOW LANGUAGE |
Establishes or displays the current language |
SET
SHOW EVENT_FACILITY |
Establishes or identifies the current run-time facility for language-specific events |
SHOW EXIT_HANDLERS | Identifies the exit handlers declared in the program |
SET
SHOW TASK |
Modifies the tasking environment or displays task information |
DISABLE
ENABLE SHOW AST |
Disables the delivery of ASTs in the program, enables the delivery of ASTs, or identifies whether delivery is enabled or disabled |
This chapter discusses the use of files for input and output (I/O) in the OpenVMS operating system and describes the aspects of OpenVMS that relate to PL/I I/O. The chapter includes the following topics:
Chapters 5, 6, 7, 8,
9 give additional information on the file system, covering
stream and record I/O, options (ENVIRONMENT and I/O statement options),
and built-in subroutines for file handling.
4.1 File Control
File constants and variables provide your program with access to files. Your program first declares a file constant or variable, and then associates the constant or variable with a file when it opens the file.
A file declaration specifies an identifier and the FILE attribute, and optionally specifies one or more file description attributes describing the type of I/O operation that will be used to process the file. Subsequent I/O statements denote the file by a FILE option.
The OPEN statement explicitly opens a PL/I file with a specified set of attributes that describe the file and the method for accessing it. A file can also be opened implicitly by a READ, WRITE, REWRITE, DELETE, PUT, or GET statement issued for a file that is not open, or by a built-in subroutine referring to a file that is not open.
When PL/I opens a file, the initial positioning depends on the type of file (record or stream), the access mode, and certain ENVIRONMENT options. File positioning for stream files and record files is described in Chapters 5 and 6, respectively.
The CLOSE statement dissociates a PL/I file from the physical file with which it was associated when it was opened. Some ENVIRONMENT options are valid in the CLOSE statement. ENVIRONMENT options are summarized in Chapter 7.
Declaring, opening, and closing files are described in more detail in
the Kednos PL/I for OpenVMS Systems Reference Manual.
4.2 Using the OpenVMS File System for I/O
When a PL/I program contains an I/O statement, for example, OPEN or READ, the compiler translates the request into a call to the appropriate OpenVMS operating system procedure.
In the OpenVMS system, I/O is performed by the following services:
Note that, although you can call RMS procedures and OpenVMS system services directly from a PL/I program, it is not normally necessary to do so. A PL/I program executed on the OpenVMS operating system has full access to RMS capabilities through the following language elements:
RMS, in turn, manages the details of communicating with the OpenVMS I/O
system to transfer data and to organize and arrange data on physical
devices.
4.2.1 PL/I Files and OpenVMS File Specifications
In a PL/I program, all I/O operations are performed on a file, using the name of a file constant or file variable. When the file is opened, PL/I associates the name of the file constant with a specific device or file on the computer system.
When a file variable is specified in an OPEN statement or in an I/O statement, the name used is that of the file constant with which the variable is currently associated. For example:
DECLARE F FILE, G FILE VARIABLE; G = F; OPEN FILE(G); |
In this example, F is a file constant and G is a file variable assigned the value of F. In the OPEN statement, PL/I uses the name F to associate PL/I file with an OpenVMS file. The default file would be F.DAT.
The following sections describe in more detail how Kednos PL/I
associates a file constant with a device or file.
4.2.2 Using the TITLE Option
When you specify the TITLE option on an OPEN statement, you can include all or part of an OpenVMS file specification to indicate the file or device to be associated with the PL/I file. The following examples illustrate the use of the TITLE option.
OPEN FILE (OUTFILE) TITLE('DB1:[PAYROLL.DAT]JANUARY.LOG;2'); |
This file specification completely defines a file on the local OpenVMS system.
OPEN FILE (PRINTFILE) PRINT TITLE('LPC0:SAMPLE.DAT'); |
This output file will be directed to LPC0:, the system printer device. The listing file will have the title SAMPLE.DAT on its burst page. OpenVMS spools low-speed I/O devices such as printers by accumulating data for the device in a file, and then queuing the file for processing when it is closed.
NAME = 'TEST'||COUNT; . . . OPEN FILE(NEWFILE) OUTPUT TITLE(NAME); |
The specification of this file is determined by the value of COUNT. For example, if COUNT is 5 when this OPEN statement executes, the file created is TEST5.DAT.
When no TITLE option is specified, PL/I supplies a default value for the file's title. The default title is the name of the file constant associated with the PL/I file. Whenever a title does not completely specify a file, PL/I takes the following steps, in order:
If the file specification that is finally achieved is invalid or
represents an illegal device or file (for example, an input file cannot
be found), the UNDEFINEDFILE condition
is signaled.
4.2.3 Using Logical Names
At DCL command level before executing a program, you can create a logical name to assign an OpenVMS file specification to the identifier of a PL/I file constant or to a value specified in a TITLE option. For example, suppose your PL/I program declares and opens a file as follows:
DECLARE INFILE FILE; . . . OPEN FILE (INFILE) RECORD INPUT; |
Before running the program, you might associate an OpenVMS file with the identifier INFILE:
$ DEFINE INFILE DB1:[TEMP]A.DAT |
The DEFINE command assigns the PL/I file INFILE the OpenVMS file specification DB1:[TEMP]A.DAT. In OpenVMS terms, the name INFILE is a logical name, and the name DB1:[TEMP]A.DAT is an equivalence name for the logical name.
You can also use the DEFINE command to specify alternate device or file equivalents for the PL/I default file constants SYSIN and SYSPRINT. For example, to redirect output for the default file SYSPRINT, you could issue the following command:
$ DEFINE SYSPRINT TEST.OUT |
While this assignment is in effect, any PL/I procedure that outputs data to SYSPRINT (without opening SYSPRINT with an explicit title) will create a file named TEST.OUT on the current default device.
Logical names can also be established by other commands. For example, you can specify a logical name for a device when you enter an ALLOCATE or MOUNT command while placing the device on line. For example:
$ ALLOCATE $_Device: MT: $_Log_Name: INFILE _MTA1: ALLOCATED |
This ALLOCATE command allocates a tape drive and establishes the logical name INFILE for it. When a PL/I program reads from the file INFILE, the system translates the name INFILE and uses the tape MTA1: as the input device.
The value specified in a TITLE option can represent a logical name. For example:
OPEN FILE(INFILE) TITLE ('NEWFILE'); |
$ DEFINE NEWFILE LARGO.TXT |
If instead of containing a colon a file specification in the TITLE option contains any of the punctuation marks that are used in OpenVMS file specifications, the file system does not translate that portion of the specification. For example:
TITLE ('STATES.') |
In this example, the file system assumes that 'STATES.' is the specification of a file name and a file type (the presence of the period indicates a null file type). It does not perform any translation.
When you enter a complete file specification for the TITLE option and you do not want the file system to attempt logical name translation, you can precede the file specification with an underscore (_). For example:
TITLE ('_DBB1:[APPLIC.FILES]MASTER.SRC') |
Process Permanent Logical Names
The system provides every user and every batch job with a default set of process logical name assignments, which are listed in Table 4-1. Because the files associated with these assignments exist for the life of the process or job, and because they are permanently open, they are called process permanent files.
Logical Name | Default Equivalence Name |
---|---|
SYS$INPUT | Input stream. For an interactive user, this is the terminal or a command procedure file; for a batch job, the input command file. |
SYS$OUTPUT | Output stream. For an interactive user, this is the terminal; for a batch job, the batch job log file. |
SYS$ERROR | Error stream. Unless overridden by the user, it is the same as SYS$OUTPUT. |
SYS$DISK | Default device. |
SYS$COMMAND | Default command stream. For an interactive user, this is the terminal; for a batch job, the batch job input command file. |
The default files associated with the GET and PUT statements, SYSIN and SYSPRINT, are defined by PL/I as follows:
Statement | PL/I File | Default Title |
---|---|---|
GET | SYSIN | SYS$INPUT |
PUT | SYSPRINT | SYS$OUTPUT |
Thus, when your program executes a GET statement that does not specify the FILE option, and if SYSIN was not explicitly opened with a title, the run-time system and the file system perform the following translations:
A similar set of associations occurs when a program executes a PUT
statement without the FILE option: the resulting output is written to
the current output file, SYS$OUTPUT.
4.2.4 Using the DEFAULT_FILE_NAME Option
Use the DEFAULT_FILE_NAME option of the ENVIRONMENT attribute to specify default values for a file specification when a file is opened.
For example:
OPEN FILE (REPORT) RECORD OUTPUT ENVIRONMENT ( DEFAULT_FILE_NAME('.LIS')); |
PL/I uses the punctuation in the DEFAULT_FILE_NAME option to determine which portion of the file specification is specified. Thus, the period (.) in the preceding example indicates that the value is a file type. An unpunctuated name is treated as a file name; a name terminated by a colon (:) is treated as a device name (and can therefore be a logical name).
When the DEFAULT_FILE_NAME option is not specified for a file, and no file type is specified, PL/I supplies the default file type DAT.
PL/I applies the value of the DEFAULT_FILE_NAME option after it establishes the file's title. Thus, in the preceding example, the title, REPORT, is established before the value '.LIS' is applied. Note that the only time a file name in a DEFAULT_FILE_NAME option is used is when the TITLE option specifies a null string; that is, the TITLE option is specified as follows:
TITLE('') |
DECLARE REMOTE_FILE FILE RECORD INPUT ENV(DEFAULT_FILE_NAME( 'RONDO::DBB2:[MALCOLM].TXT')); |
OPEN FILE(REMOTE_FILE) TITLE('ALLEGRO'); |
After logical name translation and after values supplied by the DEFAULT_FILE_NAME option, if any, are applied, the defaults that the file system applies are as follows:
Field | System Default Provided |
---|---|
Node | Local system |
Device | Current default device |
Directory | Current default directory |
File name | None |
File type | DAT |
Version number | For an input file, the most recent version; for an output file, the highest existing version number, plus 1 |
The following examples enumerate the steps in completing a file specification. All examples assume that the following logical name assignments are in effect:
TAPEFILE | = MTA0: |
STATE_NAME | = NEBRASKA |
STATES | = DMA2:[BACKUP] |
DBB1:[MALCOLM] |
In the following example, the value in the TITLE option represents the complete file specification:
DECLARE STATES FILE RECORD OUTPUT; OPEN FILE(STATES) TITLE ('_DMA2:[STATE.DATA]NEVADA.DAT;2'); |
Thus, the final specification is: _DMA2:[STATE.DATA]NEVADA.DAT;2
The following example uses several steps to obtain the file specification:
DCL STATES FILE INPUT ENVIRONMENT( DEFAULT_FILE_NAME ('[STATE.FILES].DAT')); OPEN FILE(STATES) TITLE ('MISSOURI'); |
The steps are:
The following example includes the translation of a logical name:
DECLARE STATES FILE RECORD OUTPUT; OPEN FILE(STATES) TITLE ('STATE_NAME'); |
The steps are:
In the following example, no title is specified and the default title is applied:
DCL STATES FILE RECORD OUTPUT; OPEN FILE (STATES); |
The following example specifies a tape file:
DCL TAPEFILE FILE RECORD ENVIRONMENT( DEFAULT_FILE_NAME('TAPEFILE:')); OPEN FILE(TAPEFILE) OUTPUT TITLE('TAPE1.FIL'); |
Previous | Next | Contents | Index |