| 
    
   | 
   | 
  
     
    
    
Logically deletes a record from a KSAM file.
  CALL BKDELETE (filenum, status)
 
A call to BKDELETE logically deletes the record referenced by the
logical record pointer. If reuse is not specified, then a logically
deleted record is marked for deletion, but is not physically removed
from the file. The connection between a data record marked for deletion
and the index area is severed.
    
When a file with deleted records is copied by FCOPY to a new KSAM file,
records marked for deletion by BKDELETE are not copied. This use of
FCOPY provides a means to compact a file in which many records have been
marked for deletion but physically use space in the file.
    
To use BKDELETE, the file must be open in the access mode that allows
update. If access is shared, the file must also be opened with dynamic locking
allowed (lock=1), and the file must be locked by
BKLOCK before records are deleted.
    
     
  - filenum
 
  A numeric variable containing the file number that identifies the
      file; this number was returned by the last call to BKOPEN. It
      should not be altered unless the file is closed with a successful call
      to BKCLOSE. (Required parameter)  
  - status
 
  A four-character string variable to which is returned a code that
      indicates whether or not the call to BKREWRITE was successful
      and if not, why not. The first character is set to zero if the call
      succeeds, to another value if not.  
 
    
     
    
Before calling BKDELETE, you can read the record to be deleted from
the KSAM file into the BASIC program. Using either BKREAD or
BKREADBYKEY, read the record into variables named in the read call.
When BKDELETE is successfully executed, the record is marked for
deletion. If reuse is not specified, then a logically deleted
record is marked for deletion, but is not physically removed from
the file. Any connections between the record and key entries in
the index area are severed. The associated key entries are physically
deleted from the index area although the data record remains in
the data area. Data space is not reused in order to maintain the
chronological order of the file. Because BKDELETE requires that the
record be both read and written, you must open the file for update
(access = 4) before calling this procedure.
    
After calling BKDELETE, you should check the status
parameter to make sure that the delete was successful.
    
FCOPY can also be used to permanently remove any records that were
logically deleted with BKDELETE. When you use FCOPY to copy
your KSAM file to a newly created KSAM file, only active records are copied.
Records marked for deletion are dropped from the data area during the copy.
The new file is more compact, particularly if many records had been deleted
from the old file.
    
When access is shared, the call that positions the pointer to the record to be
deleted should be included in the same pair of
BKLOCK/BKUNLOCK calls as the call to BKDELETE. This
ensures that no other user alters the record position between the call that
locates the record and the call that deletes it.
    
Figure B-2 "Deleting a Record With BKDELETE"
contains an example illustrating the logical deletion of a record from a
KSAM file.
    
Figure B-2 Deleting a Record With BKDELETE
 3240 REM ******************************************************
 3250 REM * REMOVE A RECORD FROM A KSAM FILE *
 3260 REM ******************************************************
 3270 REM
 3280 REM F IS THE FILE NUMBER OF A KSAM FILE OPENED BY A CALL TO
 3281 REM   BKOPEN
 3290 REM NOTE THAT FOR BKDELETE, BKOPEN ACCESS MODE MUST = 4 FOR
 3291 REM   UPDATE
 3295 REM
 3300 REM THE RECORD TO BE DELETED MUST FIRST BE READ...
 3305 REM AN ASSUMPTION HAS BEEN MADE THAT THE RECORD TO BE READ
 3310 REM AND DELETED CONTAINS THE SAME INFORMATION THAT WAS
 3320 REM WRITTEN IN THE BKWRITE EXAMPLE.
 3330 REM
 3340 CALL BKREAD(F,S$,B1$,B2$,A5[*],A3[*],A2[*])
 3350 REM
 3360 REM NOW DETERMINE WHETHER THE CALL WAS SUCCESSFUL
 3370 REM
 3380 IF S$[1;1]<>"0" THEN DO
 3390 REM N$ CONTAINS THE NAME OF THE KSAM FILE
 3400 REM S$ CONTAINS THE STATUS CODE SET BY THE PRECEDING CALL
 3410 PRINT "UNABLE TO READ ";N$" ERROR ";S$[1;1];" DETAIL ";S$[2]
 3420 CALL BKERROR(S$,M$)
 3430 PRINT M$
 3435 GOTO 3620
 3440 DOEND
 3450 REM
 3460 CALL BKDELETE(F,S$)
 3470 REM
 3480 REM NOW DETERMINE WHETHER THIS CALL SUCCEEDED
 3490 REM
 3500 IF S$[1;1]<>"0" THEN DO
 3510 REM N$ CONTAINS THE NAME OF THE KSAM FILE
 3520 REM S$ CONTAINS THE STATUS CODE SET BY THE PRECEDING CALL
 3530 PRINT "UNABLE TO DELETE RECORD FROM ";N$;
 3535 PRINT "ERROR ";S$[1;1];"DETAIL ";S$[2]
 3540 CALL BKERROR(S$,M$)
 3550 PRINT M$
 3560 GOTO 3620
 3570 DOEND
 3575 PRINT "DELETED RECORD CONTAINS ";B1$;B2$;
 3576 MAT PRINT A5
 3577 MAT PRINT A3,A2
 3580 REM
 3590 REM THE PROGRAM CONTINUES
 
    
  
     
    
     
   |