Assign new values to field variables
REPLACE <idField> WITH <exp> [, <idField2> WITH <exp2>...] [<scope>] [WHILE <lCondition>] [FOR <lCondition>]
<idField> is the name of the field variable to be assigned a new value. If <idField> is prefaced with an alias, the assignment takes place in the designated work area.
WITH <exp> defines the value to assign to <idField>.
<scope> is the portion of the current database file to REPLACE. The default is the current record, or NEXT 1. Specifying a condition changes the default to ALL records in the current work area.
WHILE <lCondition> specifies the set of records meeting the condition from the current record until the condition fails.
FOR <lCondition> specifies the conditional set of records to REPLACE within the given scope.
REPLACE is a database command that assigns new values to the contents of one or more field variables in the current record in the specified work areas. The target field variables can be character, date, logical, memo, or numeric. REPLACE performs the same function as the assignment operator (:=) except that it assumes that an unaliased reference is to a field variable. This means that you can assign new values to field variables using assignment statements provided that the field variable references are prefaced with an alias, the FIELD alias, or declared using the FIELD declaration statement.
The default scope of REPLACE is the current record unless a scope or condition is specified. If a scope or condition is specified, the replace operation is performed on each record matching the scope and/or condition.
Warning! When you REPLACE a key field, the index is updated and the relative position of the record pointer within the index is changed. This means that REPLACEing a key field with a scope or a condition may yield an erroneous result. To update a key field, SET ORDER TO 0 before the REPLACE. This ensures that the record pointer moves sequentially in natural order. All open indexes, however, are updated if the key field is REPLACEd.
In a network environment, REPLACEing the current record requires an RLOCK(). REPLACEing with a scope and/or condition requires an FLOCK() or EXCLUSIVE USE of the current database file. If a field is being REPLACEd in another work area by specifying its alias, that record must also be locked with an RLOCK(). Refer to the “Network Programming” chapter for more information.
. This example shows a simple use of REPLACE: USE Customer NEW APPEND BLANK USE Invoices NEW APPEND BLANK // REPLACE Charges WITH Customer->Markup * Cost,; Custid WITH Customer->Custid,; Customer->TranDate WITH DATE() . This example uses assignment statements in place of the REPLACE command: FIELD->Charges := Customer->Markup * FIELD->Cost FIELD->Custid := Customer->Custid Customer->TranDate := DATE()
COMMIT, FLOCK(), RLOCK()