Command UPDATE Foundation

Updates data in the current work area using data from another work area.

Syntax
UPDATE FROM <cAlias> ON <cKeyExpr> [RANDOM] ;
    REPLACE <cFieldname1> WITH <Expression1> ;
         [, <cFieldname2> WITH <Expression2>...]
Parameters
<cAlias>
<cAlias> is the alias name of the second work area whose data records are used in the update of the current work area. It can be specified as a literal or as a character expression in parentheses.
<cKeyExpr>
<cKeyExpr> is an expression which must provide the same value in both work areas so that the data can be updated in the current work area. The current work area must be sorted or indexed by <cKeyExpr>. The expression is tested in both work areas. If the value is the same in both work areas, records are updated in the current work area.
<cFieldname>
<cFieldname> is the name of a field variable in the current work area to which the value <Expression> is assigned.
<Expression>
<Expression> is an expression whose value is assigned to the field <cFieldname>. The data type of <Expression> must match the field's data type. If <Expression> is a field variable in the second work area, <cAlias> (the alias name) and the alias operator must be included.
RANDOM
Normally, the second work area <cAlias> must be sorted by the same key expression <cIndexKey> as the current work area. If this is not the case, the option RANDOM must be specified. Including this option indicates that the records in the source work area appear in a different order and are not sorted or indexed according to the key expression.
Description

The command UPDATE updates the records in the current work area using values from the records of a second work area <cAlias>. An update only occurs when the expression <cKeyExpr> provides the same value in both work areas. This assumes that a controlling index with the index expression <cKeyExpr> is active and that no multiple key values exist in this index. The records of the second work area are processed sequentially and the value of <cKeyExpr> of the second work area is searched for in the current work area using SEEK. If a matching record is found, the fields specified in the list <Fieldname1> to <cFieldnameN> are updated with the values from <Expression1> to <ExpressionN>.

When the option RANDOM is specified, the records of the second work area can appear in any order. This requires more time for the update. If RANDOM is not specified, the records of the second work area must be sorted (logically or physically) in the order defined by <cKeyExpr>.

If records in either of the two work areas are marked for deletion, they are ignored if SET DELETED is set to ON. As long as SET DELETED is OFF, all records are considered and they retain their "Deleted" status.

If the command UPDATE is used in a multi-user application in network operation, the file in the current work area must be locked or opened exclusively. The file in the second work area does not need to be locked since only read access of it occurs.

The functional equivalent of UPDATE is the function DbUpdate().

Examples
UPDATE
// The example shows a common use for the command 
// UPDATE. Data in a permanent file is updated 
// using current data from a temporary file. The 
// data in the temporary file is then deleted. 

PROCEDURE Main 

   USE Sold ALIAS Sold NEW EXCLUSIVE 
   INDEX ON PartNo TO SoldA 

   USE Part ALIAS Part NEW EXCLUSIVE 
   INDEX ON PartNo TO PartA 

   UPDATE ON PartNo FROM Sold ; 
     REPLACE OnStock   WITH OnStock   - Sold->Number , ; 
             TotalSold WITH TotalSold + Sold->Number 

   SELECT Sold 
   ZAP 

   CLOSE DATABASES 

RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.