|
|
Many of the KSAM procedures use a logical record pointer to
indicate the current record in the file. This pointer points to a key value in
the index area that identifies the current record in the data area. The
particular key used, if the file has more than one key, is the key specified in
the current procedure or the last procedure that referenced a key.
Procedures that use pointers are either pointer-dependent or
pointer-independent. Pointer-dependent procedures expect the
pointer to be positioned at a particular record in order to execute correctly.
Pointer-independent procedures, on the other hand, execute regardless of where
the pointer is positioned and, in most cases, they position the pointer.
Table A-1 Positioning the Logical Record Pointer
Procedure Name |
Pointer- Dependent |
Position of Pointer After Execution of Procedure |
CKSTART | NO | Points to key whose value was
specified in call. |
CKREADBYKEY | NO | Points to key whose value was
specified in call. |
CKWRITE | NO | Points to key whose value is next
in key sequence to key value in record just written. |
CKREAD | YES | Pointer remains positioned to key
value for record just read; unless next call is to
CKREAD, or to CKREWRITE followed by CKREAD, in
which case, next CKREAD moves pointer to next key in key sequence
before reading the record. |
CKDELETE | YES | Points to next key value in
ascending sequence following key value in record just deleted. |
CKREWRITE | YES (sequential mode)
NO (random or dynamic mode) | Pointer remains positioned to key value
for record just modified, unless any key value in record was changed; in
this case, it points to next key in ascending sequence after the key in the
modified record. |
Particular care must be taken when using the logical record pointer during
shared access (the file was opened with CKOPENSHR). If more than one
user opens the same file, one user may modify the record pointer. This causes
other users to access the data record.
To avoid this problem, you should always lock the file in a shared environment
before calling a procedure that sets the pointer and leave the file locked
until all procedures that depend on the pointer have been executed. Thus, if
you want to read the file sequentially, delete a record, or modify a record,
you should lock the file, call a procedure that sets the pointer (such as
CKSTART), and then call CKREAD, CKDELETE, or
CKREWRITE. When the operation is complete, you can then unlock the
file to give other users access to it.
The file KSAMFILE illustrated in Figure
A-2 "Representation of KSAMFILE Used in COBOL Examples" is used in all
subsequent examples associated with the COBOL procedure calls.
Figure A-2 Representation of KSAMFILE Used in COBOL Examples
:BUILD KSAMFILE;REC=-74,,F,ASCII;KSAMXL;&
: KEY=(B,3,20;B,23,8,DUP)
:BUILD KSAMFILE;REC=-74,,F,ASCII;KSAM64;&
: KEY=(B,3,20;B,23,8,DUP)
A File Description in Working Storage for Figure A-2 appears below.
File Description in Working Storage (Figure A-2).
WORKING-STORAGE SECTION
77 RECSIZE PIC S9(4) COMP VALUE 74.
77 RESULT PIC 9(4) VALUE 0.
01 REC.
03 FILLER PIC XX VALUE SPACES.
03 NAME PIC X(20).
03 PHONE PIC X(8).
03 OTHERDATA PIC X(44).
01 DAT.
03 NAME PIC X(20).
03 PHONE PIC X(8).
03 OTHERDATA PIC X(44).
01 FILETABLE.
03 FILETABLE PIC S9(4) COMP VALUE 0.
03 FILENAME PIC X(8) VALUE "KSAMFILE".
03 I-O-TYPE PIC S9(4) COMP VALUE 0.
03 A-MODE PIC S9(4) COMP VALUE 0.
03 PREV-OP PIC S9(4) COMP VALUE 0.
01 STAT.
03 STATUS-KEY-1 PIC X.
03 STATUS-KEY-2 PIC X.
|