OLDVAL( ) Function Example

The following example demonstrates how you can use OLDVAL( ) to return original field value for a field in a buffered table. A table named employees is created and INSERT – SQL is used insert the value "Smith" into the cLastName field.

MULTILOCKS is set to ON, a requirement for table buffering. CURSORSETPROP( ) is used to set the buffering mode to optimistic table buffering (5).

The original value of the cLastName field (Smith) is displayed and then the cLastName field is modified with REPLACE. The new value of the cLastName field (Jones) is displayed. The original value of the cLastName field (Smith) is displayed with OLDVAL( ). TABLEUPDATE( ) is then used to commit changes to the table. The updated value of the cLastName field (Jones) is then displayed.

CLOSE DATABASES
CLEAR

* Create new table and add blank record
CREATE TABLE employee (cLastName C(10)) 
APPEND BLANK

* Insert initial value
INSERT INTO employee (cLastName) VALUES ("Smith")

* Enable and set table buffering
SET MULTILOCKS ON  && Allow table buffering
=CURSORSETPROP("Buffering", 5, "employee" )  && Enable table buffering

* Display initial value
=MESSAGEBOX("Original cLastName value: "+ cLastName, 0, "Results")

* Change record value and display results
REPLACE cLastName WITH "Jones"
=MESSAGEBOX("Modified cLastName value: "+ cLastName, 0, "Results")

* Store the old value of the field to cTemp variable and display results
cTemp=OLDVAL("cLastName", "employee")
=MESSAGEBOX("Original cLastName value: "+ cTemp, 0, "Results")

* Update table and display final value
=TABLEUPDATE(.T.)
=MESSAGEBOX("Final cLastName value: "+ cLastName, 0, "Results")

* Close and delete example table file
USE
DELETE FILE employee.dbf