Using KSAM XL: 900 Series HP 3000 Computer Systems > Appendix B BASIC/V IntrinsicsBKREWRITE |
|
Changes the contents of a record in a KSAM file.
A call to BKREWRITE replaces the contents of an existing record with new values. The record to be rewritten is the last record accessed by a call to BKREAD, BKREADBYKEY, or BKSTART. To use BKREWRITE, the file must be open in the access mode that allows update. If access is shared, it must also be opened with dynamic locking allowed, and the file must be locked by BKLOCK before records are rewritten.
After calling BKREWRITE, you should always check the status parameter to make sure that the rewrite was successful. Upon successful completion of BKREWRITE, new values replace the data in the last record read to or written from the BASIC program. The new data may change every value in the previously read record including the primary key value. If you want to replace a record with a particular key value, you should locate and read the record with BKREADBYKEY or BKSTART. To rewrite a series of records you should read the records with BKREAD. When the data in the parameterlist of BKREWRITE is shorter in total length than the data in the record being rewritten, there is less total data in the rewritten record. In order to maintain the key sequence of all keys, defined values should be written to the location of all keys, both the primary key and any alternate keys.
The example in Figure B-9 “Rewriting Record in KSAM File with BKREWRITE” writes new values to a record originally written in Figure B-13 “Writing to a KSAM File with BKWRITE” and read in Figure B-5 “Reading From a KSAM File with BKREAD”. The new values fill an array that had undefined values in the last five elements, now defined as two arrays A3 and A2 by the BKREAD call. The primary key value 23 in location 2 is unchanged. The record read by BKREAD contained the following values: After being rewritten by BKREWRITE, it contains the following values: When access is shared, the call to BKREAD, BKREADBYKEY, or BKSTART that locates the record to be rewritten should be included in the same pair of BKLOCK/BKUNLOCK calls as the call to BKREWRITE. This ensures that no other user alters the record pointer between the call that locates the record and the call that rewrites it. If you want to sequentially rewrite all records in a chain of records with duplicate keys, locate the first record in the chain with BKREADBYKEY. Then call BKREWRITE to modify this record. If no key value (the selected key or any other) is modified, subsequent calls to BKREWRITE will modify the next sequential records in the chain of duplicate keys. If, however, any key has been changed, the modified key is written to the end of the chain and the next sequential record is one with the next higher key value. In this case, to rewrite all records with duplicate keys, precede each call to BKREWRITE by a call to BKREADBYKEY. Figure B-9 Rewriting Record in KSAM File with BKREWRITE
|