COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

27 Tape Input and Output
HP COBOL batch programs must often read or write files that are on magnetic tape (tape files).
If you need further information on reading and writing tape files, see the Guardian Programmer’s
Guide.
If you want to archive disk files on magnetic tape, use the operating environment’s BACKUP utility.
To restore archived disk files from a tape back to a disk (which you must do before an HP COBOL
program can read them), use the operating environment’s RESTORE utility. For information on the
BACKUP and RESTORE utilities, see the Guardian User’s Guide.
Reading and Writing Tape Files
An HP COBOL program can read and write unlabeled tape files, labeled tape files, and tape files
of types other than HP.
By default, the shortest record an HP COBOL program can write to a tape file is 24 bytes. If you
need shorter records, use the COBOL_SETMODE_ routine to set function 52 (see the Guardian
User’s Guide).
Preventing Prereading
HP COBOL prereads tapes; that is, it initiates a new read operation after processing the last (or
only) record in a block. Prereading can overlap I-O with program processing. If you do not want
this to happen, verify that the records of a tape file will not be preread by opening the file for
timed I-O (include a TIME LIMITS phrase in the OPEN statement or use the command PARAM
WAITED-IO). For an explanation of prereading file records, see Prereading File Records (page 836).
You cannot give a tape file the access mode I-O or the exclusion mode PROTECTED or SHARED.
Saving Tape and Time
You can save both tape and time by blocking tape file records efficiently—that is, by specifying
that each physical record is to contain more than one logical record (the default is one logical
record per physical record).
Because consecutive physical records are separated by an interrecord gap, longer physical records
mean fewer interrecord gaps (less wasted tape). Because the tape drive must start and stop each
time you read or write a physical record, having fewer interrecord gaps save time.
Interrecord gap size depends on tape drive model, but the typical interrecord gap is about 0.6
inch (1.5 cm). If you are writing 1,600 bytes per inch—19,200 bytes, or characters, per foot (30
cm) of tape—then each interrecord gap occupies 960 bytes (1,600 bytes per inch*0.6 inch =
960 bytes).
Suppose that each logical record is 80 bytes. If each physical record contains only one logical
record (the default), you can write 18.5 physical records (18.5 logical records) per foot of tape
(19,200 bytes/(80 bytes per physical record + 960 bytes per physical record) = 18.5 records).
If, instead, you specify 10 logical records per physical record, giving each physical record 800
bytes, you can write 10.9 physical records (109 logical records) per foot of tape. If you specify
50 logical records per physical record, giving each physical record 4 KB, you can write 3.87
physical records (193.5 logical records) per foot of tape.
You specify the number of logical records or characters per physical record (block) with a BLOCK
CONTAINS clause in the file description entry of the file associated with the tape drive. The BLOCK
CONTAINS clause works if these conditions are met:
The file’s organization is sequential.
The file has fixed-length records.
838 Tape Input and Output