[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
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:
IDENTIFICATION DIVISION. PROGRAM-ID. PROGX. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 X PIC X(28). PROCEDURE DIVISION. A. MOVE "ABC*ABC*ABC ABC@ABCABC" TO X. INSPECT X CONVERTING "ABC" TO "XYZ" AFTER "*" BEFORE "@". DISPLAY X. STOP RUN. X before INSPECT executes X after INSPECT executes ABC*ABC*ABC ABC@ABCABC ABC*XYZ*XYZ XYZ@ABCABC |
Programmers most commonly make the following errors when writing INSPECT statements:
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:
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.
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 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 |