You can populate a temp-table by copying records into it from the database. You can copy the entire record or select fields. To copy a record from the database table to the temp-table you must:
  1. Create a temp-table record.
  2. Copy the record from the database (source) into the temp-table record (target).

Syntax for creating a temp-table record

The basic syntax for creating a temp-table record is the same as for creating a database table record:
CREATE ttName.
Where ttName is the name of the temp-table. This creates the temp-table record.

See the CREATE statement for more detail.

Syntax for buffer-copy

Use the following syntax to copy a database record buffer into a temp-table record buffer:

BUFFER-COPY source TO target.

See the BUFFER-COPY statement for more detail.

The following example code shows how to populate the ttCustomer temp-table from the database. Note that the BUFFER-COPY only copies the matching fields; fields in the database or temp-table that do not match the other are ignored.

DEFINE TEMP-TABLE ttCustomer NO-UNDO     // Define the temp-table
  FIELD CustNum AS INTEGER
  FIELD Name AS CHARACTER
  FIELD City as CHARACTER
  FIELD State as CHARACTER
  FIELD Country as CHARACTER. 

FOR EACH Customer WHERE Customer.Country = "USA":  // Iterate through Customer table 
  CREATE ttCustomer.     // Create the temp-table record
  BUFFER-COPY Customer TO ttCustomer.  // Copy database record into temp-table record
  DISPLAY ttCustomer.
END.

/* return the temp-table to the UI client */