COBOL Manual for TNS and TNS/R Programs

Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs522555-006
28-19
Creating and Using Queue Files
Creating and Using Queue Files
A queue file is an indexed file (and therefore, a key-sequenced file) that can function
as a queue. Processes can queue and dequeue records in a queue file.
Queue files contain variable-length records that are accessed by values in designated
key fields. Unlike other key-sequenced files, queue files have prime keys but cannot
have alternate keys. The prime key for a queue file includes an 8-byte timestamp; you
can add a user key if desired. The disk process inserts the timestamp when each
record is inserted into the file, and maintains the timestamp during subsequent file
operations.
Topics:
Creating a Queue File
Opening a Queue File
Reading a Queue File
Writing to a Queue File
For more information about queue files, see the Enscribe Programmer’s Guide.
Creating a Queue File
Before you can use a queue file, you must create it (with the FUP CREATE command,
for example). Its prime key must have at least 8 bytes (for the timestamp). If you want
to add a user key, describe it before describing the timestamp, as in Example 28-9.
Opening a Queue File
Open a queue file for shared access and SYNCDEPTH 0; for example:
OPEN queue-file INPUT SHARED SYNCDEPTH 0
Example 28-9. Creating a Queue File With a Timestamp and a User Key
SELECT queue-file ASSIGN to queuef
ORGANIZATION IS INDEXED
ACCESS MODE IS SEQUENTIAL
RECORD KEY IS queue-key
FD queue-file
RECORD IS VARYING FROM 10 TO 100 CHARACTERS
DEPENDING ON rec-len.
01 queue-rec.
02 queue-key.
03 user-key PIC XX.
03 timestamp PIC X(8).
02 the-rest PIC X(90).