HPlogo KSAM/3000 Reference Manual: HP 3000 MPE/iX Computer Systems > Chapter 6 USING KSAM FILES IN BASIC PROGRAMS

BKDELETE

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

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. 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.

PARAMETERS

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. (Refer to Status Parameter discussion earlier in this section.)

USING BKDELETE

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.)

Shared Access

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

 



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 BKOPEN 

3290 REM NOTE THAT FOR BKDELETE, BKOPEN ACCESS MODE MUST = 4 FOR 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 THF 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 
Feedback to webmaster