APPEND example
The following function is used when adding data to a table. It attempts to recycle records by looking for a blank deleted record. If one is not found the APPEND BLANK command is used to create a new record.
PROCEDURE NewRec
set deleted off
if seek( " " ) .and. deleted( ) .and. rlock( )
recall
else
append blank
endif
set deleted on
First, DELETED is turned OFF so that deleted records can be found. (The normal operation of the application has DELETED ON.) The SEEK( ) function looks for a record with a character key that starts with a blank space, which indicates a blank record; a valid index key cannot be blank. The table must be ordered on a character field when the function is called. If a blank record is found, the DELETED( ) function makes sure it’s deleted, and an RLOCK( ) is attempted to prevent anyone else from grabbing the same record at the same time.
If all of these things are successful, the record is RECALLed and made available for use. Otherwise, a new blank record is created with APPEND BLANK. Either way, DELETED is turned back ON and the function is completed, leaving the record pointer at the new or recycled record.
To see the function that deletes records for recycling, see the example for BLANK.