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

Appendix B 251
BASIC/V Intrinsics
BKREADBYKEY
keylocation
parameters.
The key value in the record to be read must exactly match the specified
keyvalue
. Unlike
BKSTART, the only relation between the value in the record and the value in the call is that
of equality. If duplicate key values are allowed in the key being sought, then the first
record with a matching key value is read by BKREADBYKEY. To read the remaining records
with duplicate key values, you should use BKREAD.
NOTE
Each variable in
parameterlist
is filled to its current physical length before
proceeding to the next variable.
The example in Figure B-6. uses BKREADBYKEY to read the first record found with the value
23 starting in byte 2. Since this is the file written by BKWRITE in Figure B-13., the records
in the file are identical including the keys and only the first record is read.
Figure B-6. Reading a Record Located by Key Value with BKREADBYKEY
2220 REM *****************************************************
2230 REM * READ BY KEY FROM A KSAM FILE *
2240 REM *****************************************************
2250 REM
2260 REM F IS THE FILE NUMBER OF A KSAM FILE
2270 REM OPENED BY A CALL TO BKOPEN
2280 REM
2290 REM AN ASSUMPTION HAS BEEN MADE THAT THE RECORD TO BE READ
2300 REM CONTAINS THE SAME INFORMATION THAT WAS WRITTEN IN THE
2310 REM WRITE EXAMPLE.
2320 REM
2330 REM AN ADDITIONAL ASSUMPTION IS THAT THE DESIRED KEY VALUE
2340 REM STARTS AT CHARACTER 2 AND HAS THE VALUE "23".
2350 REM
2360 CALL BKREADBYKEY(F,S$,"23",2,B1$,B2$,A5[*],A3[*],A2[*])
2370 REM
2380 REM NOW DETERMINE WHETHER THIS CALL HAS SUCCEEDED
2390 REM
2400 IF S$[1;1]<>"0" THEN DO
2410 REM N$ CONTAINS THE NAME OF THE KSAM FILE
2420 REM S$ CONTAINS THE STATUS CODE SET BY THE PRECEDING CALL
2430 PRINT "UNABLE TO READBYKEY ";N$;" ERROR ";S$[1;1];" DETAIL "S$[2]
2440 CALL BKERROR(S$,M$)
2450 PRINT M$
2460 GOTO 3620
2470 DOEND
2480 REM
2490 REM THE CONTENTS OF B1$="1", OF B2$="23".
2500 REM THE CONTENTS OF A5(1) THROUGH A5(5) ARE INTEGERS 1 THROUGH 5
2510 REM THE CONTENTS OF A3 AND A2 ARE UNKNOWN.
2520 REM
2530 REM ECHO WHAT WAS READ
2540 REM
2550 PRINT "RECORD READ = ";B1$,B2$
2560 MAT PRINT A5
2562 MAT PRINT A3,A2
2570 REM
2580 REM THE PROGRAM CONTINUES