[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
User Manual


Previous Contents Index

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 (Alpha, I64)

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.

On OpenVMS Alpha or I64, a stream file will also be generated under certain situations if you compiled /NOVFC. See Section B.4.3 for more information. <>

6.1.4 File Design

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:

  • Record format---For relative files (see Section 6.1.2)
    Relative files can contain either fixed-length records or variable-length records. However, the I/O system calculates a cell size equal to the maximum record size plus overhead bytes, resulting in fixed-length storage for relative files (see the Relative File Organization section in Section 6.1.1). Once created, relative records can be accessed sequentially, randomly, or dynamically.
  • Storage Medium
    You can access sequential, relative, and indexed files on disk. Be careful to use a disk pack that is large enough to meet your current and future needs. You can also access sequential files, unlike relative and indexed files, on magnetic tape and unit record devices (for example, on printers).
  • Allocation (see Chapter 15)
    On OpenVMS, you can optimize data storage at the time of file creation and file extension. <>
  • Bucket size---For relative files (see the Relative File Organization section in Section 6.1.1)
    You can optimize the packing of cells into buckets by ensuring that the cell size is evenly divisible into the bucket size.
  • Maximum number of records---For relative files (see the Relative File Organization section in Section 6.1.1)
  • Key scheme---For relative files (see the Relative File Organization section in Section 6.1.1)
  • Speed---For indexed files (see the Indexed File Organization section in Section 6.1.1)
    You can maximize the speed with which the program processes data.
  • Space---For indexed files (see the Indexed File Organization section in Section 6.1.1)
    You can minimize file size, disk space, and memory requirements to run your program.
  • Shared access---For indexed files (see the Indexed File Organization section in Section 6.1.1)
    Consider who is going to use the data and how they will access it.
  • Ease of design---For indexed files (see the Indexed File Organization section in Section 6.1.1)
    You can minimize the amount of time spent writing the application.
  • Compiler limitations (see Appendix A)
    Consider the logical and physical limits imposed by the HP COBOL compiler.

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 expect.

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:

  • OPEN
  • READ
  • START
  • UNLOCK
  • DELETE
  • CLOSE

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.

A file connector is an HP COBOL data structure that contains information about a file. The file connector links a file name and its associated record area to a physical file.

Defining a File Connector with SELECT and ASSIGN

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 the ASSIGN clause, you specify a nonnumeric literal or data name that associates the file name with a file specification. This value must be a complete file specification.

Example 6-8 and Example 6-9 show the relationships between the SELECT statement, the ASSIGN clause, and the FD 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).
           .
           .
           .

Note

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.


Previous Next Contents Index