table.COPY Function

Syntax

V Copy(), Specify the required values in the Copy dot variable, then use the following command: <TBL>.COPY()

Arguments

Copy.set

Type "C". If copying a table, set copy.set to a NULL string (""). If copying a set, specify the name of the set in the copy.set parameter.

Copy.db

Type "C". Destination table filename.

Copy.dd

Type "C"

.T. (TRUE) = Copy the data dictionary (field rules, layouts, saved settings, etc.).
.F. (FALSE) = Do not copy the data dictionary.
Copy.records

Type "L"

.T. (TRUE) = Copy all of the currently selected records (i.e., the active range, index, or query).
.F. (FALSE) = Do not copy records (i.e., an empty destination table is created).
Copy.delete_o_dd

Type "L". The target table that you specify may already exist, and may have a data dictionary. If you specify that the data dictionary from the source table should not be copied, you can specify whether the target table's pre-existing dictionary (if any) should be retained, or deleted.

.T. (TRUE) = Delete the target table's pre-existing dictionary.
.F. (FALSE) = Retain the pre-existing dictionary.
Copy.fields

Type "N". The number of fields to be copied.

Copy.field1 ... Copy.fieldN

Type "C". The name of each field to be copied

Description

Copy all or some of the fields from the table to another table or set.

Discussion

The <TBL>.COPY() method is a high-level utility used to copy all or some of the fields from a table or set to a new table. The table to be copied is specified by the object pointer, <TBL>. In the case of a set, the <TBL> object pointer refers to the primary table in the set.

Example 

This script copies the selected fields from the current table to a new table.

dim tbl as P
dim filename as C
filename = ui_get_file("Copy To:","Tables(*.DBF)","","N")
if filename = "" then
    end
end if
tbl = table.current()
copy.db = filename
copy.set = ""
copy.dd = .T.
copy.records = .T.
copy.delete_o_dd = .T.
copy.fields = 8
copy.field1 = "SALUTATION"
copy.field2 = "FIRST_NAME"
copy.field3 = "LAST_NAME"
copy.field4 = "ADDRESS_1"
copy.field5 = "ADDRESS_2"
copy.field6 = "CITY"
copy.field7 = "STATE_PROV"
copy.field8 = "ZIP"
tbl.copy()

This script copies selected fields from a set to a new table.

dim tbl as P
tbl = table.open("c:\a5\a_sports\invoice.set")
copy.db = "c:\a5\a_sports\copy.dbf"
copy.set = "c:\a5\a_sports\invoice.set"
copy.dd = .T.
copy.records = .T.
copy.delete_o_dd = .T.
copy.fields = 5
copy.field1 = "inv_head->inv_no"
copy.field2 = "customer->last_name"
copy.field3 = "inv_item->prod_no"
copy.field4 = "inv_item->quantity"
copy.field5 = "product->description"
tbl.copy()

See Also