HP OpenVMS Systems Documentation
If you have multiple record-length descriptions for a file and omit either the RECORD VARYING clause or the RECORD CONTAINS TO clause, all records written to the file will have a fixed length equal to the length of the longest record described for the file, as in Example 6-7.
|Example 6-7 Defining Fixed-Length Records with Multiple Record Descriptions|
. . . FD PARTS-MASTER. 01 PARTS-REC-1 PIC X(200). 01 PARTS-REC-2 PIC X(300). 01 PARTS-REC-3 PIC X(400). 01 PARTS-REC-4 PIC X(500). . . . PROCEDURE DIVISION. . . . 100-WRITE-REC-1. MOVE IN-REC TO PARTS-REC-1. WRITE PARTS-REC-1. GO TO ... 200-WRITE-REC-2. MOVE IN-REC TO PARTS-REC-2. WRITE PARTS-REC-2. GO TO ... . . .
Writing PARTS-REC-1, PARTS-REC-2, PARTS-REC-3 or PARTS-REC-4 produces
records equal in length to the longest record, PARTS-REC-4. Note that
this is not variable-length I/O.
6.1.3 Print-Control Records
Print-control files contain record-advancing information with each record. These files are intended for eventual printing, but are created on disk by your HP COBOL program. The compiler generates print-control records when you use the WRITE AFTER ADVANCING, the LINAGE, or the APPLY PRINT-CONTROL clause, or if you create a Report Writer file or use ASSIGN TO PRINTER (on Tru64 UNIX systems).
On OpenVMS Alpha and OpenVMS I64, in any of the preceding cases, if you compile /NOVFC, the compiler does not generate print-control records, but generates stream files instead.
On OpenVMS, HP COBOL places explicit form-control bytes directly into the file. You must use the /NOFEED option on the DCL PRINT command to print a print-control file. <>
Stream files contain records of different length, delimited by a record terminator.
The compiler generates a stream record formatted file when you use the ORGANIZATION IS LINE SEQUENTIAL clause in the File-Control Division. This record format is useful for files created by text editors.
The difficulty of design is proportional to the complexity of the file organization. Before you create your sequential, relative, or indexed file applications, you should design your files based on these design considerations:
On OpenVMS, for more information about file design, see Chapter 15.
For OpenVMS Alpha and OpenVMS I64 systems you can also refer to the
Guide to OpenVMS File Applications. <> Chapter 15 contains instructions on
optimizing the file design for indexed files. With indexed files, in
particular, if you accept all the file defaults instead of carefully
designing your file, your application may run more slowly than you
6.2 Identifying Files and Records from Within Your HP COBOL Program
Before your program can perform I/O on a file, your program must identify the file to the operating system and specify the file's organization and access modes. A program must follow these steps whenever creating a new file or processing an existing file.
You use a file description entry to define a file's logical structure and associate the file with a file name that is unique within the program. The program uses this file name in the following COBOL statements:
The program uses the record name for the WRITE and REWRITE statements.
6.2.1 Defining a File Connector
You must establish a link between the file connector your program uses and the file specification that the I/O system uses. You create this link and define a file connector by using the SELECT statement with the ASSIGN clause and optionally specifying the VALUE OF ID clause or by using logical names or environment variables.
Your program must include a SELECT statement, including an ASSIGN clause, for every file description entry (FD) it contains. The file name you specify in the SELECT statement must match the file name in the file description entry.
In Example 6-8, because the file name specified in the FD entry is DAT-FILE, all I/O statements in the program referring to that file or to its associated record must use the file name DAT-FILE or the record name DAT-RECORD. The I/O system uses the ASSIGN clause to interpret DAT-FILE as REPORT.DAT on OpenVMS systems, and REPORT on Tru64 UNIX systems. The default directory is used on OpenVMS systems, and the current working directory is used on Tru64 UNIX systems.
|Example 6-8 Defining a Disk File|
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT DAT-FILE ASSIGN TO "REPORT". . . . DATA DIVISION. FILE SECTION. FD DAT-FILE. 01 DAT-RECORD PIC X(100). . . .
On OpenVMS systems, if no file type is supplied, HP COBOL supplies the default file extension DAT. On Tru64 UNIX systems, the extensions dat and idx are appended, but only in the case of indexed files.
The I/O statements in Example 6-9 refer to MYFILE-PRO, which the ASSIGN clause identifies to the operating system as MARCH.311. Additionally, the operating system looks for the file in the current directory on the magnetic tape mounted on MTA0: on an OpenVMS system.
|Example 6-9 Defining a Magnetic Tape File (OpenVMS)|
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT MYFILE-PRO ASSIGN TO "MTA0:MARCH.311" . . . DATA DIVISION. FILE SECTION. FD MYFILE-PRO. 01 DAT-RECORD PIC X(100). . . . PROCEDURE DIVISION. A000-BEGIN. OPEN INPUT MYFILE-PRO. . . . READ MYFILE-PRO AT END DISPLAY "end". . . . CLOSE MYFILE-PRO. <>
Example 6-10 achieves the same result as Example 6-9, but on Tru64 UNIX. The I/O statements in Example 6-10 refer to MYFILE-PRO, which the ASSIGN clause identifies to the operating system as a magnetic tape file. The file is named in the Data Division VALUE OF ID clause as MARCH.311.
|Example 6-10 Defining a Magnetic Tape File (Tru64 UNIX)|
ENVIRONMENT DIVISION INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT MYFILE-PRO ASSIGN TO REEL. . . . DATA DIVISION. FILE SECTION. FD MYFILE-PRO VALUE OF ID "MARCH.311". 01 DAT-RECORD PIC X(100). . . . PROCEDURE DIVISION. A000-BEGIN. OPEN INPUT MYFILE-PRO. . . . READ MYFILE-PRO AT END DISPLAY "end". . . . CLOSE MYFILE-PRO.
For each OPEN verb referring to a file assigned to magnetic tape, the user is prompted to assign the file to a magnetic tape device. These device names are in the form /dev/rmt0(a,l,m,h) ... /dev/rmt31(a,l,m,h) and correspond to special files on the system that refer to mass storage tape devices. For more information on tape devices, refer to the mtio(7) Tru64 UNIX manual page.