REPLACE FROM ARRAY
Topic group Related topics
Transfers data stored in an array to the fields of the current table.
REPLACE FROM ARRAY <array>
[FOR <condition 1>]
[WHILE <condition 2>]
[FIELDS <field list>]
The name of the array that you want to transfer data from.
FOR <condition 1>
WHILE <condition 2>
The scope of the command. The default scope is REST. The dimensions and size of <array> also controls which records are updated.
FIELDS <field list>
Restricts data replacement to the fields specified by <field list>.
Specifies that all affected indexes are rebuilt once the REPLACE FROM ARRAY operation finishes. Without REINDEX, dBASE Plus updates all open indexes after replacing each record in the scope. When replacing many or all records in a table that has multiple open indexes, REPLACE FROM ARRAY executes faster with the REINDEX option.
Use REPLACE FROM ARRAY to transfer values from an array into fields of the current table. REPLACE FROM ARRAY treats the columns in a one-dimensional array like a single record of fields; and treats a two-dimensional array like a table, with the rows (the first dimension) of the array like records, and the columns (the second dimension) like fields.
For a one-dimensional array, REPLACE FROM ARRAY will replace the first record in the command scope that matches the specified condition. If there is no specified scope and condition, the current record is replaced.
For a two-dimensional array, REPLACE FROM ARRAY will attempt to copy each row in the array to a record in the command scope that matches the specified condition until the end-of-scope or all rows of the array have been copied, in which case the record pointer is left at the last record replaced. As with the REPLACE command, be careful if are changing the values of the key fields of the current master index.
If the array has more columns than the table has fields, the additional elements are ignored. Similarly, if a two-dimensional array has more rows than can be copied to the table, the additional rows are ignored.
REPLACE FROM ARRAY does not replace memo (or binary) fields; these fields should not be counted when sizing the array, and cannot be included in the <field list>.
The data types of the array must match those of corresponding fields in the table you are replacing. If the data type of an array element and a corresponding field don't match, an error occurs.
Use a loop to copy the elements of the array into the value properties of the Field objects in the rowset’s fields array, nested in another loop to traverse the rowset if necessary.