Functions and Directives

Function DbCopyStruct() Foundation

Creates a file with the same structure as the file open in a work area.

DbCopyStruct( <cFilename>, [<aFieldNames>] ) --> lSuccess
<cFilename> is a character string containing the name of the file to be created using the file structure from a work area. When the file name does not include a file extension, the default extension predetermined by the current database engine (DBE) is used. The default file extension of the DBFDBE is ".DBF".
<aFieldNames> := { [<cField,...>] }
The optional argument <aFieldNames> specifies an array containing the names of the specific fields to be used in creating the file <cFilename>. Each array element must contain a character string <cField> indicating a field name. If this argument is not included, all fields from the work area are copied into the new file.

The function DbCopyStruct() returns a logical value indicating whether the operation was successful. If this value equals .T. (true), a file could be created with the same structure as the file open in the work area.


The database function DbCopyStruct() creates the file <cFilename>using the field definitions from a work area. By specifying the array <aFieldNames>, the number of the fields in the target file can be limited.

Using DbCopyStruct(), temporary files can be created to hold a subset of data during specific processing. DbCopyStruct() is also used to create files for handling data transactions.

Creates a subset of records

// In the example, a subset of a stock list file is created. The 
// structure of the stock on hand file is copied into an order 
// file and all records from the stock file whose count 
// falls short of the minimal level are copied into the order 
// file. This file is printed out and then deleted. 


   DbUseArea( .T., , "Stock" ) 
   DbCopyStruct( "Order" ) 
   DbUseArea(, , "Order" ) 

   DbImport( "Stock", ; 
            {|| FIELD->InStock < FIELD->MinLevel } ) 


   FErase( "Order.dbf" ) 

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.