GETNEXTMODIFIED( ) Function Example

The following example demonstrates how you can use GETNEXTMODIFIED( ) to determine which records in a table have been changed. MULTILOCKS is set to ON, a requirement for table buffering. The customer table in the testdata database is opened, and CURSORSETPROP( ) is then used to set the buffering mode to optimistic table buffering (5).

SKIP is issued to move the record pointer to the second record, and the cust_id field is modified with REPLACE. GETNEXTMODIFIED(0) is used to display the record number of the next modified record (2, the second record), starting from the beginning of the table. TABLEREVERT( ) is used to return the table to its original state, and GETNEXTMODIFIED(0) is used again to display the record number of the next modified record (0, indicating that no records have been modified).

CLOSE DATABASES
CLEAR

OPEN DATABASE SYS (HOME(2) + 'data\testdata')
SET MULTILOCKS ON  && Allow table buffering
USE Customer     && Open customer table
=CURSORSETPROP("Buffering", 5, "customer")  && Enable table buffering

SKIP  && Move record pointer to the second record

* Change field contents
REPLACE cust_id WITH "***"

* Call MESSAGEBOX function with results of GETNEXTMODIFIED
=MESSAGEBOX("Record " + ALLTRIM(STR(GETNEXTMODIFIED(0))) + ;
   " has changed.",0,"Results")

* Revert table and display results with MESSAGEBOX
=TABLEREVERT(.T.)  && Discard all table changes
nChange=GETNEXTMODIFIED(0)
IF nChange=0
   =MESSAGEBOX("Record(s) have been reverted.",0,"Results")
ELSE
   =MESSAGEBOX("Record " + ALLTRIM(STR(GETNEXTMODIFIED(0))) + ;
    " has changed.",0,"Results")
ENDIF