Using KSAM/XL and KSAM 64 (32650-90886)

Appendix A 211
COBOL Intrinsics
CKSTART
if so, the comparison proceeds as if the file key were truncated on the right to the same
length as
key length
. If no record can be found whose key value satisfies the comparison,
an invalid key condition is returned to
status
; that is,
status
is set to 23.
If you use CKSTART to position the pointer before reading or updating the file sequentially
in a shared environment, you must lock the file with a call to CKLOCK before calling
CKSTART. Then, after you have completed the sequential operations, you can unlock the file
with a call to CKUNLOCK. If you wait to lock the file until after the call to CKSTART, another
user can change the structure of the index area so that the position of the pointer becomes
invalid for any subsequent call to a procedure that depends on the pointer position.
For the following examples, four new items must be added to the WORKING-STORAGE
SECTION in Figure A-2.; otherwise, the same WORKING-STORAGE SECTION is used.
The new items are:
77 RELOP PIC S9(4) COMP.
77 KEYVAL PIC X(20).
77 KEYLOC PIC S9(4) COMP.
77 KEYLENGTH PIC S9(4) COMP.
Each of these items is assigned the value appropriate to the operation to be performed by
statements in the PROCEDURE DIVISION. Note that the length of array
KEYVAL
can be
made shorter by assigning a value less than 20 to
KEYLENGTH
but it cannot be made longer
than 20 characters. Since there is no key in KSAMFILE longer than 20 characters, this
allows comparison to be made on the longest key.
The following example shows the statements needed to display the records in KSAMFILE in
order by the alternate key
PHONE
that starts in location 23 and has a length of 8 characters.
It assumes the file is open for input or input/output and that the access mode is sequential.
It also assumes the FINISH procedure from the CKCLOSE example.
NEW-POSITION.
MOVE 2 TO RELOP.<---
find key value greater than or equal to
KEYVAL
MOVE "000-0000" TO KEYVAL.
MOVE 23 TO KEYLOC.
MOVE 8 TO KEYLENGTH.
CALL "CKSTART" USING FILETABLE, STAT, RELOP, KEYVAL, KEYLOC,
KEYLENGTH.
IF STAT = "23" THEN GO TO FINISH.<---
no record found
IF STATUS-KEY-1 = "0" THEN GO TO READ-BY-PHONE.<---
lowest key
value found
DISPLAY "CKSTART ERROR, STATUS", STAT.
IF STATUS-KEY-1 = "9" THEN
CALL "CKERROR" USING STAT, RESULT
DISPLAY "ERROR NUM", RESULT.
GO TO FINISH.
READ-BY-PHONE.
CALL "CKREAD" USING FILETABLE, STAT, REC, RECSIZE,
IF STATUS-KEY-1 = "1" THEN GO TO FINISH.<----
end-of-file
IF STATUS-KEY-1 = "O" THEN
DISPLAY REC;
ELSE DISPLAY "CKREAD ERROR,STATUS=", STAT