Copy_Records

See Also: Implementing Callback Functions, Copy_DB, DF_RUNTIME_PROGRESS_FREQUENCY

Purpose

The Copy_Records command is used to copy records from one database table to another.

Syntax

Copy_Records {from-table-number} To {to-table-number} [{num-records}] ;

                                   [Using {index-num}] ;

                                   [Callback {callback-object}]

Argument Explanation

{from-table-number} Is the filelist number of the database table from which records are to be copied.

{to-table-number} Is the filelist number of the destination database table to which records are to be copied.

{num-records} Is the maximum number of records to be copied. If this parameter is not specified, all records will be copied. Also, a value of 0 will copy all records.

{index-num} Is the index that will be used to determine the order of the records to be copied. If not specified, records are copied in the order of recnum.

{callback-object} Is a handle to an object that will receive the Callback message during the sort operation. Refer to Implementing Callback Functions for more information.

What It Does

Copy_Records copies {num-records} records from {from-table-number} to {to-table-number}. If the Using parameter is used, records are copied using the specified {index-num}. If not, then recnum is used. If any copied record contains a field value matching the value in any other record and the field participates in an on-line unique index, Error 28 Duplicate records not allowed in table will be returned, and the record will not be copied.

This command copies record data between database tables of the same or different types and/or structures. Data is copied from each field in the source table for which a field of the same name exists in the target table. Other than name, the fields do not have to have the same size or type attributes, since data conversions will take place automatically.

Data may be truncated in the destination table if the target field is not large enough to contain all of the converted data. In addition, when converting an ASCII, text, or binary field to a numeric or date field, the target field will contain a zero if the source field was not a valid number or date as required.

If the record buffer of the {from-table-number} table is active, the copy starts from the active record and proceeds until {num-records} records have been copied to the target table. If the record buffer of the source table is inactive, the copy starts at the first record (based on {index-num}) in the source table.

If {num-records} is zero, all records from the starting point to the end of the source table will be copied. If {num-records} is greater than the number of records from the starting point to the end of the source table, only the records from the starting point to the end will be copied.

After each record is copied, the callback function (if specified) will be called and passed a string containing the number of records copied.

Example

Object oCopyRecords is a Array

    Function Callback  String sText  Integer iLogicalID  Returns Integer

        showln sText

        // Tell operation to continue

        Function_Return False

    End_Function

 

    Procedure DoRecordCopy

        // This is needed to return a callback for each record

        Set_Attribute DF_RUNTIME_PROGRESS_FREQUENCY to 1

        Copy_Records Prospect.File_Number To Customer.File_Number ;

                     0  Callback Self

    End_Procedure

End_Object

If the record buffer of Prospect is inactive when Procedure DoRecordCopy is called, all records in Prospect will be copied to Customer, in recnum order. Note that only fields with the same name in both tables get copied.

Notes