Copies data from non-memo fields of the current table, overwrites elements of an existing array, and moves the record pointer to the last record copied.

Syntax

COPY TO ARRAY <array>
[<scope>]
[FOR <condition 1>]
[WHILE <condition 2>]
[FIELDS <field list>]

<array>

A reference to the target array

<scope>
FOR <condition 1>
WHILE <condition 2>

The scope of the command. The default scope is ALL, until <array> is filled.

FIELDS <field list>

Copies data from the fields in <field list> in the order of <field list>. Without FIELDS, dBASE Plus copies all the fields the array can hold in the order they occur in the current table.

Description

Use COPY TO ARRAY to copy records from the current table to an existing array. COPY TO 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.

To copy the fields from a single record, create a one-dimensional array the same size as the number of fields to copy. To copy all the fields in the record, use FLDCOUNT( ) to get the number of fields; for example

a = new Array( fldcount( ) )

To copy multiple records, create a two-dimensional array. The first dimension will indicate the number of records. The second dimension indicates the maximum number of fields. To copy all the records, use RECCOUNT( ) to get the number of records; for example

a = new Array( reccount( ), fldcount( ) )

If the array has more columns than the table has fields, the additional elements will be left untouched. Similarly, if a two-dimensional array has more rows than the table, the additional rows are left untouched.

COPY TO ARRAY does not copy memo (or binary) fields; these fields should not be counted when sizing the target array.

COPY TO ARRAY copies records in their current order and, within each record, in field order unless you use the FIELDS option to specify the order of the fields to copy.

After copying, the record pointer is left at the last record copied, unless the array has more rows than the table has records. In this case, the record pointer is left at the end-of-file.

OODML

Use two nested loops, the first to traverse the rowset, and the second to copy the value properties of the Field objects in the rowset’s fields array to the target array’s elements.