Performs a bulk copy of a source record to a target record by copying each source field to the target field of the same name. You can specify a list of fields to exclude from the bulk copy, or a list of fields to include in the bulk copy.

Syntax

BUFFER-COPY source [ { EXCEPT | USING } field ... ]
  TO target [ ASSIGN assign-expression ... ] [ NO-LOBS ] [ NO-ERROR ]
source
The source database table, buffer, temp-table, or work table.
EXCEPT field ...
A list of space-separated source fields to exclude from the bulk copy.
USING field ...
A list of space-separated source fields to include in the bulk copy. The USING option is simply a positive version of the EXCEPT option.
TO target
The target database table, buffer, temp-table, or work table.
ASSIGN assign-expression
A space-separated list of any valid ABL ASSIGN statements (without the EXCEPT option, which BUFFER-COPY already provides). BUFFER-COPY performs each assign-expression and automatically excludes the field on the left side ("destination") of each assign-expression from the bulk copy-except for field extents (subscripted fields). If a field extent appears on the left side of an assign-expression, BUFFER-COPY does not automatically exclude that extent (such as customer.mnth-sales[1]) or the field as a whole (such as customer.mnth-sales) from the bulk copy.
NO-LOBS
Directs the AVM to ignore large object data when copying records that contain BLOB or CLOB fields.
CAUTION: Using this option can create the potential for errors in your data and lead to inappropriate results. Therefore, before using this option, you must understand the nature of your data and be sure that logic using this option will not result in inconsistent or out-of-date data in the database.
NO-ERROR
The NO-ERROR option is used to prevent the statement from raising ERROR and displaying error messages.
Note: Compound assignment operators (+=, -=, *=, /=) can be used with the BUFFER-COPY statement. For more information, see += Addition assignment operator, -= Subtraction assignment operator, *= Multiplication assignment operator, and /= Division assignment operator.

Example

The following example uses BUFFER-COPY twice. The first time, a Customer database record is copied into a temp-table record. The second time, the ASSIGN option is used with BUFFER-COPY to assign the ItemName and TotalWeight fields of an OrderLine record.

DEFINE TEMP-TABLE ttCustomer LIKE Customer. //sports2020.Customer
DEFINE TEMP-TABLE ttOline LIKE OrderLine //sports2020.OrderLine
  FIELD ItemName AS CHARACTER
  FIELD TotalWeight AS DECIMAL.    

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

FOR EACH ttCustomer:
    DISPLAY ttCustomer.CustNum ttCustomer.NAME ttCustomer.Country.
END.

FOR EACH OrderLine NO-LOCK WHERE Orderline.OrderNum = 10125,
  Item OF OrderLine NO-LOCK:
    CREATE ttOline.
    BUFFER-COPY OrderLine TO ttOline
      ASSIGN ttOline.ItemName = Item.ItemName
        ttOline.TotalWeight = OrderLine.Qty * Item.Weight.
END.

FOR EACH ttOline:
  DISPLAY ttOline.OrderNum ttOline.ItemNum ttOline.ItemName ttOline.TotalWeight.
END.

Notes

  • At compile time, BUFFER-COPY:
    • Fails to compile if any source-target field pair is not type compatible
    • Excludes from the bulk copy all EXCEPT field fields, and all assign-expression fields on the left side of the assignment
    • Automatically excludes fields that appear in the source but not the target from the bulk copy
    • Tries to bind unqualified field names that appear in the EXCEPT and USING options to the source buffer
  • At run time, BUFFER-COPY:
    • Creates a target record if none already exists and executes any applicable CREATE triggers
    • Assigns all matching fields that do not appear in the EXCEPT or ASSIGN options
    • Performs each assign-expression in the ASSIGN option, one-by-one
  • The BUFFER-COPY statement, like the VALIDATE statement, must appear within the scope of a FIND, a FOR EACH, or a CREATE statement that references the source table.
  • If a BUFFER-COPY statement references a target buffer for the first time, ABL regards this reference as a "free reference" and scopes the buffer to the nearest enclosing block that can scope records. For more information on free references, see the topics on block properties in Develop ABL Applications.
  • With respect to transaction processing, ABL treats a BUFFER-COPY statement the same way it would treat equivalent ASSIGN statements. For more information on transaction processing, see the topics on transactions in Develop ABL Applications.
  • The compiler's XREF facility automatically creates a REFERENCE for each field in the fields list, a TABLE-REFERENCE for the source and target buffers, ACCESS and UPDATE references for any fields in the ASSIGN option, and ACCESS (or UPDATE) references for each source (or target) field that participates in the bulk copy.
  • When copying records that contain a BLOB or CLOB field, the AVM copies the object data associated with the source record to the target record. If the BLOB or CLOB field in the source record contains the Unknown value (?), the AVM stores the Unknown value (?) in the BLOB or CLOB field of the target record. If the target record already has object data associated with it, the AVM deletes that object data before copying the new object data.
  • Use the NO-LOBS option with the BUFFER-COPY statement to ignore large object data when copying records that contain BLOB or CLOB fields. More specifically:
    • When you copy a source record to a new target record, the AVM sets the value of the BLOB or CLOB field in the target record to the Unknown value (?).
    • When you copy a source record to an existing target record, the AVM does not change the value of the BLOB or CLOB field in the existing target record.

    You can also use the EXCEPT option to exclude BLOB and CLOB fields from the copy.

See also

BUFFER-COMPARE statement , NO-ERROR option