HP OpenVMS Systems Documentation

Content starts here

User Manual

Previous Contents Index

5.3.7 Using the CONVERTING Option

When an INSPECT statement contains a CONVERTING phrase, that statement selectively replaces characters or groups of characters in the designated item; it executes as if it were a Format 2 INSPECT statement with a series of ALL phrases. (Refer to the INSPECT statement formats in the HP COBOL Reference Manual.)

An example of the use of the CONVERTING phrase follows:

01 X PIC X(28).
            AFTER "*" BEFORE "@".

    X before INSPECT executes      X after INSPECT executes


5.3.8 Common INSPECT Statement Errors

Programmers most commonly make the following errors when writing INSPECT statements:

  • Leaving the FOR out of an INSPECT...TALLYING statement
  • Using the word WITH instead of BY in the REPLACING phrase
  • Failing to initialize the tally counter
  • Omitting the word ALL before the comparison character-string

Chapter 6
Processing Files and Records

The HP COBOL I/O system offers you a wide range of record management techniques while remaining transparent to you. You can select one of several file organizations and access modes, each of which is suited to a particular application. The file organizations available through HP COBOL are sequential, line sequential, relative, and indexed. The access modes are sequential, random, and dynamic.

This chapter introduces you to the following HP COBOL I/O features:

For information about low-volume or terminal screen I/O using the ACCEPT and DISPLAY statements, see Chapter 11 and refer to the HP COBOL Reference Manual.

The operating system provides you with I/O services for handling, controlling, and spooling your I/O needs or requests. HP COBOL, through the I/O system, provides you with extensive capabilities for data storage, retrieval, and modification.

On the OpenVMS Alpha and OpenVMS I64 operating systems, the HP COBOL I/O system consists of the Run-Time Library (RTL), which accesses Record Management Services (RMS). (On OpenVMS VAX, COBOL-generated code accesses RMS directly.) Refer to the OpenVMS Record Management Utilities Reference Manual and the OpenVMS Record Management Services Reference Manual for more information about RMS. <>

On the Tru64 UNIX operating system, the HP COBOL I/O system consists of the Run-Time Library (RTL) and facilities of Tru64 UNIX. In addition, the facilities of a third-party ISAM package are required for any use of ORGANIZATION INDEXED. <>

6.1 Defining Files and Records

A file is a collection of related records. You can specify the organization and size of a file as well as the record format and physical record size. The system creates a file with these characteristics and stores them with the file. Any program that accesses a file must specify the same characteristics as those that the system stored for that file when creating it.

A record is a group of related data elements. The space a record needs on a physical device depends on the file organization, the record format, and the number of bytes the record contains.

File organization is described in Section 6.1.1. Record format is described in Section 6.1.2.

6.1.1 File Organization

HP COBOL supports the following four types of file organization:

  • SEQUENTIAL---This organization requires that records be referenced in sequence from the first record to the last. This organization is useful for programs that normally access each record serially. (See the Sequential File Organization section in this chapter.)
  • LINE SEQUENTIAL (Alpha, I64)--- This organization is essentially the same as sequential. Line sequential allows you to treat files as collections of variable length records, with each record containing one line of printable characters. This organization is useful for programs that access files created by text editors and similar programs. (See the Line Sequential File Organization (Alpha, I64) section in this chapter.) <>
  • RELATIVE---This organization lets you access records randomly, or sequentially by record number values. While this organization is more flexible than sequential organization, it is less flexible than indexed organization because you cannot insert a record in the middle of your file unless you have an empty cell to contain it. (See the Relative File Organization section in this chapter.)
  • INDEXED---This organization lets you access records randomly or sequentially, by primary and alternate key values. This is a useful way to organize a file in which records will be added, changed, or deleted upon demand. (See the Indexed File Organization section in this chapter.)


On Tru64 UNIX, a third-party product is required for INDEXED runtime support. Refer to the Read Before Installing... letter for up-to-date details on how to obtain the INDEXED runtime support. <>

Table 6-1 summarizes the advantages and disadvantages of these file organizations.

Table 6-1 HP COBOL File Organizations---Advantages and Disadvantages
File Organizations Advantages Disadvantages
Sequential Uses disk and memory efficiently Allows sequential access only
  Provides optimal usage if the application accesses all records sequentially on each run Allows records to be added only to the end of a file
  Provides the most flexible record format  
  Allows READ/WRITE sharing  
  Allows data to be stored on many types of media, in a device-independent manner  
  Allows easy file extension  
Line Sequential
(Alpha, I64)
Most efficient storage format Allows sequential access only
  Compatible with text editors Used for printable characters only
    Open Mode I/O is not allowed
Relative Allows sequential, random, and dynamic access Allows data to be stored on disk only
  Provides random record deletion and insertion Requires that record cells be the same size
  Allows READ/WRITE sharing  
Indexed Allows sequential, random, and dynamic access Allows data to be stored on disk only
  Allows random record deletion and insertion on the basis of a user-supplied key Requires more disk space
  Allows READ/WRITE sharing Uses more memory to process records
  Allows variable-length records to change length on update Generally requires multiple disk accesses to randomly process a record
  Allows easy file extension  

Sequential File Organization

Sequential input/output, in which records are written and read in sequence, is the simplest and most common form of I/O. It can be performed on all I/O devices, including magnetic tape, disk, terminals, and line printers.

Sequential files consist of records that are arranged in the order in which they were written to the file. Figure 6-1 illustrates sequential file organization.

Figure 6-1 Sequential File Organization

Sequential files always contain an end-of-file (EOF) indication. On magnetic tapes, it is the EOF mark; on disk, it is a counter in the file header that designates the end of the file. HP COBOL statements can write over the EOF mark and, thus, extend the length of the file. Because the EOF indicates the end of useful data, HP COBOL provides no method for reading beyond it, even though the amount of space reserved for the file exceeds the amount actually used.

Previous Next Contents Index