COBOL Manual for TNS and TNS/R Programs
Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs—522555-006
28-45
Creating a File Having Alternate Keys From an
HP COBOL Program
Creating a File Having Alternate Keys From an HP COBOL
Program
At times, it is necessary within an HP COBOL process to create and operate on a file
that has alternate keys. Suppose the file must be named and built during execution.
The only way to do this is through a series of steps involving a few Enscribe routines:
1. Declare the records of the file in a file description entry.
2. Use the FILE_CREATELIST_ procedure to create the primary file in conformance
with the specification in the file-control entry and the file description.
3. Use the FILE_CREATELIST_ procedure to create the alternate-key file in
conformance with the specification of the keys in the file-control entry and the
record description for the file.
4. Open the loadfile and use it.
Suppose you have a server process that must create a private, indexed file having one
alternate key.
The file-control entry and file description entry are:
SELECT T-file-1 ASSIGN TO "ISFILE"
ORGANIZATION IS INDEXED
RECORD KEY IS K1
ALTERNATE RECORD KEY IS AK1
ACCESS MODE IS DYNAMIC
FILE STATUS IS Fs
...
FD T-file-1 LABEL RECORDS OMITTED.
01 T-rec-1.
02 K1.
03 K1-fp PIC XX.
03 FILLER PIC X.
02 Ak1.
03 Fp PIC X(5).
03 Lp PIC X(5).
02 FILLER PIC X(20).
02 rw-flag PIC X(4).
02 T-rec-no PIC 999.
...
Note. This explanation does not elaborate all the data definitions and all the code necessary
to manage the creation of an indexed file with an alternate key. Only the significant
declarations and code are shown. In some cases, the code mentions data items that are
presumed to have been defined and given values by statements not shown.