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

Appendix A 207
COBOL Intrinsics
CKREWRITE
Regardless of mode, an invalid key condition occurs if an alternate key value in the record
to be written duplicates a corresponding alternate key for which duplicates are prohibited.
When rewriting a record, try to avoid specifying an alternate key value that may duplicate
a value existing in the file unless duplicates are allowed for the key. A duplicate key
condition where duplicates are not allowed causes
status
to be set to 22 and the procedure
is not executed.
Use CKSTART to position the current record pointer to the start of the file. Then read each
record in sequence and set its non-key items to blanks.
The first example is of a sequential update that clears the value of an item in each record
of the file. The second example searches the file for a record whose primary key has a
particular value in order to change the alternate key for that record. Both examples
assume the WORKING-STORAGE SECTION from Figure A-2. and the FINISH procedure
from CKCLOSE.
NOTE
If the file was opened for shared access with a call to CKOPENSHR, then the file
should be locked with a call to CKLOCK before the call to CKSTART. The file
should be unlocked with a call to CKUNLOCK only when the final record is
updated, probably in the FINISH procedure.
DATA DIVISION.
.
.
.
WORKING-STORAGE SECTION. \
77 RELOP PIC S9(4) COMP.|
77 KEYVAL PIC X(20). |<---
items required by CKSTART
77 KEYLOC PIC S9(4) COMP.|
77 KEYLENGTH PIC S9(4) COMP.|
.
.
.
PROCEDURE DIVISION.
START.
MOVE 2 TO I-O-TYPE.
MOVE 0 TO A-MODE.
CALL "CKOPEN" USING FILETABLE, STAT.
.
.
. <---
check status
UPDATE-FILE.
MOVE 1 TO RELOP.
MOVE "000-0000" TO KEYVAL.<---
set up CKSTART parameters to start
MOVE 23 TO KEYLOC.
reading at lowest alternate key
value
MOVE 8 TO KEYLENGTH.
CALL "CKSTART" USING FILETABLE, STAT, RELOP, KEYVAL, KEYLOC,
KEYLENGTH.
IF STATUS-KEY-1="0" THEN
GO TO READ-RECORD;
ELSE
DISPLAY "CKSTART ERROR, STATUS", STAT.