COBOL Manual for TNS and TNS/R Programs

Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs522555-006
28-47
Creating a File Having Alternate Keys From an
HP COBOL Program
Example 28-14. Dynamic File Assignment
...
MOVE FUNCTION LENGTH (T-rec-1) TO Lrl-v
MOVE FUNCTION LENGTH (K1) TO Key-length-v, A-key-off
MOVE FUNCTION LENGTH (AK1) TO A-key-len
MOVE FUNCTION LENGTH (Values-array) TO Values-length
* Create the primary file
ENTER "FILE_CREATELIST_" USING File-name,
File-name-len,
Item-list,
Number-of-items,
Values-array,
Values-length,
Error-item
GIVING Create-error
IF Create-error NOT = 0
DISPLAY "Creation failed with error ", Create-error,
" in parameter " Error-item
STOP RUN
END-IF
* Create the alternate key file
* The key length has to be 2 greater than the real one
COMPUTE Akf-key-len = 2 + A-Key-len
* The record length has to be 5 greater than the real key length
COMPUTE Akf-rec-len = 5 + A-Key-len
ENTER "FILE_CREATE_" USING Ak-file-name-v,
Ak-file-name-len-v,
OMITTED,
OMITTED,
OMITTED,
OMITTED,
3,
OMITTED,
Akf-rec-len,
OMITTED,
Akf-key-len,
0
GIVING Create-error
IF Create-error NOT = 0
DISPLAY "AK creation failed with error ", Create-error,
" in parameter " Error-item
STOP RUN
END-IF