Copies records from the current table to another table or text file.

Syntax

COPY TO <filename>
[<scope>]
[FOR <condition 1>]
[WHILE <condition 2>]
[FIELDS <field list>]
[[TYPE] DBASE | DBMEMO3 | PARADOX | SDF |
  DELIMITED [WITH
    <char> | BLANK]] |
[[WITH] PRODUCTION]

TO <filename>

Specifies the name of the table or file you want to create.

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

The scope of the command. The default scope is ALL.

FIELDS <field list>

Specifies which fields to copy to the new table.

[TYPE] DBASE | DBMEMO3 | PARADOX | SDF |
DELIMITED [WITH <char> | BLANK]

Specifies the format of the file to which you want to copy data. The TYPE keyword is included for readability only; it has no effect on the operation of the command. The following table provides a description of the different file formats that are supported:

Type

Description

DBASE

A dBASE table. If you don't include an extension for <filename>, dBASE Plus assumes a .DBF extension.

DBMEMO3

Table (.DBF) and memo (.DBT) files in dBASE III PLUS format.

PARADOX

A Paradox table. If you don't include an extension for <filename>, dBASE Plus assumes a .DB extension.

SDF

A System Data Format text file. Records in an SDF file are fixed-length, and the end of a record is marked with a carriage return and a linefeed. If you don't specify an extension, dBASE Plus assumes .TXT.

DELIMITED

A text file with fields separated by commas. These files are also referred to as CSV (Comma Separated Value) files. Character fields are delimited with double quotation marks when they are not empty() or null.

Each carriage return and linefeed indicates a new record. If you don't specify an extension, dBASE Plus assumes .TXT.

DELIMITED
WITH <char>

Indicates that character data is delimited with the character <char> instead of with double quotes. For example, if delimited with a single quote instead of a double quote, the clause would be:

DELIMITED WITH '

DELIMITED
WITH BLANK

Indicates that data is separated with spaces instead of commas, with no delimiters.

[WITH] PRODUCTION

Specifies copying the production .MDX file along with the associated table. This option can be used only when copying to another dBASE table.

Description

Use COPY to copy all or part of a table to a file of the same or a different type. If an index is active, COPY arranges the records of the new table or file according to the indexed order.

The COPY command does not copy a _DBASELOCK field in a table that you've created with CONVERT.

The COPY command does not copy standard, custom or referential integrity properties to the new file. Standard properties include default, maximum, minimum and required.

COPY TO [WITH] PRODUCTION results in a table whose natural order mimics that of the active index being copied.

COPY TO [WITH] PRODUCTION also changes the "date of last update" (datestamp) in the headers of newly created files, to reflect the date they were created (in other words, today's date).

Use the COPY TABLE command to make a copy of a table, including all its index, memo, and other associated files, if any. Unlike the COPY command, the table does not have to be open, and an exact copy of all the records is always made. COPY TABLE copies all field property information and, unlike COPY TO [WITH] PRODUCTION, does not change the datestamp in headers of newly created .dbf and .mdx files

When COPYing to text files, SDF or DELIMITED, non-character fields are written as follows:

Numbers are written as-is.

Logical or boolean fields use the letter T for true and F for false.

Dates are written in the format YYYYMMDD.

If you COPY a table containing a memo field to another dBASE table, dBASE Plus creates another file with the same name as the table but having a .DBT extension, and copies the contents of the memo field to it. If, however, you use the SDF or DELIMITED options and COPY to a text file, dBASE Plus doesn't copy the memo fields.

Deleted records are copied to the target file (if it's a dBASE table) unless a FOR or WHILE condition excludes them or unless SET DELETED is ON. Deleted records remain marked for deletion in the target dBASE table.

You can use COPY to create a file containing fields from more than one table. To do that, open the source tables in different work areas and define a relation between the tables. Use SET FIELDS TO to select the fields from each table that you want to copy to a new file. Before you issue the COPY command, SET FIELDS must be ON and you must be in the work area in which the parent table resides.

The COPY command does not verify that the files you build are compatible with other software programs. You may specify field lengths, record lengths, number of fields, or number of records that are incompatible with other software. Check the file limitations of your other software program before exporting tables using COPY.

OODML

Use the UpdateSet object’s copy( ) method. Set filter options in the source rowset.