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

Writing to a Queue File
To write to a queue file, be sure that it exists and then open it for input and output; for example:
OPEN queue-file I-O SHARED SYNCDEPTH 0
In the file-control entry, specify ACCESS MODE IS RANDOM.
After the file is open, use any form of the WRITE statement to write to it. The value that you write
to the timestamp field does not matter, because the system replaces that value with its own
timestamp.
Establishing Starting Points in Files
When you read a file using a key, you sometimes want to start at the record associated with a
given key value and continue to read successive records according to the value of that key until
you reach the record associated with a certain other value of that key. The key can be the prime
key of a file of relative or indexed organization or an alternate key of any structured file.
Such a key is termed the key of reference. The mechanisms in HP COBOL that implement this form
of reading are the DYNAMIC access mode, the START statement, and the sequential form of the
READ statement (a READ statement with a NEXT phrase).
Key of Reference
COBOL defines the “key of reference” as “the prime or alternate key currently being used to access
records within an indexed file.” HP COBOL extends that definition to “the prime or alternate key
currently being used to access records within an indexed or relative file, or the alternate key
currently being used to access records in an entry-sequenced file.
Enscribe uses the term “access path” for the sequence of records accessed by the key of reference.
You establish the key of reference by executing a START statement or a READ statement containing
a KEY phrase. In a START statement, the key can specify the identifier of an entire key field or the
identifier of a leftmost subordinate of the key field. For example, in the record in Example 285, if
LAST-NAME, DEPARTMENT-NUMBER, and JOB-TITLE are alternate keys, you can use LN5, LN10,
LN15, DN3, and J-T-PORTION as keys.
Example 285 Key of Reference
01 PERSONNEL-REC.
03 NAME-FIELDS.
05 LAST-NAME.
07 LN1ST. PIC X.
07 LN2ND. PIC X.
...
07 LN25TH. PIC X.
05 FIRST-NAME PIC X(25).
05 M-I-NAME PIC X.
03 DEPARTMENT-NUMBER PIC 9999.
03 DN REDEFINES DEPARTMENT-NUMBER.
05 DN3 PIC 999.
05 FILLER PIC X.
03 JOB-TITLE.
05 J-T-PORTION.
07 J-T PIC X OCCURS 1 TO 25 TIMES
DEPENDING ON J-T-LENGTH.
66 LN5 RENAMES LN1ST THRU LN5TH.
66 LN10 RENAMES LN1ST THRU LN10TH.
66 LN15 RENAMES LN1ST THRU LN15TH.
After you have established the key of reference, you can execute sequential READ statements (READ
NEXT statements) to read successive records according to that key: records in a relative file in
ascending record-number order, records in an indexed file in ascending prime-key order, or records
Establishing Starting Points in Files 869