COBOL Manual for TNS and TNS/R Programs
Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
9-188
READ for Sequential or Dynamic Access
•
Variable-Length Records
An Enscribe structured file is always capable of containing variable-length records.
The file has a stated maximum allowable record length, but records can vary from
a length of 0 up to the stated maximum. If the file is written as variable-length
records, the COBOL program can read it under a declaration of
RECORD CONTAINS rec-1 TO rec-2 CHARACTERS
or
RECORD IS VARYING IN SIZE FROM rec-1 TO rec-2 CHARACTERS
DEPENDING ON rec-size
(although in COBOL you cannot explicitly state rec-1 as 0). The only way to
determine the length of the record read is to use the DEPENDING phrase of the
VARYING clause. The contents of the record area beyond the data fetched by any
given read is undefined.
Other HP products are capable of writing records of length 0 in such files. A
COBOL program can read a record of length 0; however, in an entry-sequenced
file with fixed-length records, such a record is ignored and the next record is
immediately read.
•
Setting the Value of the DEPENDING Item (Variable-Length Records)
When the file has variable-length records whose sizes are reflected by the rec-
size item specified in the RECORD VARYING clause of the file description entry,
the value associated with the rec-size at the beginning of a read operation is
ignored. The read operation obtains the record and moves the number of character
positions the record contains into rec-size.
•
Use of wait-time
wait-time must be either a numeric data item or a numeric literal, signed or
unsigned, having a maximum of seven digits to the left of the decimal. Any
fractional part to the right of the decimal is rounded to two decimal places; for
example:
05 WAIT-FILEX PIC 9(7)V9(2) COMPUTATIONAL.
A nonnegative value of wait-time indicates the time interval within which the
operation must complete. If the record is locked or reading a process and the
operation does not complete within that time interval, it is terminated, and no error
message is generated. The file-status item is set to “30,” the GUARDIAN-ERR
register is set to 40, and the value of the file position indicator becomes undefined.
The file position indicator is undefined because it is not clear at what point of the
read operation wait-time was exceeded. There is no guarantee that you can try
the operation again.
If the value of wait-time is -1 or the TIME LIMIT phrase is not present, no time
limit is placed on the operation. The program can wait indefinitely for its request to
complete. Any other negative value has the same effect as -1.