|
|
KSAM/3000 Reference Manual: HP 3000 MPE/iX Computer Systems > Chapter 6 USING KSAM FILES IN BASIC PROGRAMSBKDELETE |
|
Logically deletes a record from a KSAM file.
A call to BKDELETE logically deletes the record referenced by the logical record pointer. A logically deleted record is marked by two delete characters (ASCII code 255) in the first two character positions in the record. The deletion characters indicate that the record is inaccessible, although it is not physically removed from the file. The connection between a data record marked for deletion and the key file 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.
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 record into variables named in the read call. When BKDELETE is successfully executed, the first two characters of the record just read are marked for deletion. Then the record is written back to the file. Any connections between the record and key entries in the key file are severed. The associated key entries are physically deleted from the key file although the data record remains in the data file. 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. In the event that you deleted a record in error, you can recover the information in the data record by copying the data file with the NOKSAM option of FCOPY. You can copy the data file to another non-KSAM file or to the list device. With this FCOPY option, the deleted records as well as active records are copied. In order to make use of this recovery procedure, you may want to leave the first two characters of any KSAM record empty of data. In particular, you should not specify keys in those two characters. 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 file during the copy. The new file is more compact, particularly if many records had been deleted from the old file. (Refer to FCOPY description in section II for more information.) 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 insures that no other user alters the record position between the call that locates the record and the call that deletes it. (Refer to Table 6-3 “Positioning the Logical Record Pointer” for a list of the procedures that position the pointer and those that depend on the pointer.) Figure 6-2 “Deleting a Record With BKDELETE” contains an example illustrating the logical deletion of a record from a KSAM file. Figure 6-2 Deleting a Record With BKDELETE
|
|