Try OpenEdge Now
skip to main content
ABL Essentials
Defining and Using Temp-tables : Using a temp-table as a parameter : Using BUFFER-COPY to assign multiple fields

Using BUFFER-COPY to assign multiple fields

The BUFFER-COPY statement, as the name implies, copies like-named fields from one record buffer to another. You can extend the statement to either include or exclude fields from the copy, and to do other assignments of fields with different names and assignments involving expressions. Here is the syntax of the BUFFER-COPY statement:


BUFFER-COPY source-buffer[{ EXCEPT | USING }field ...]
  TO target-buffer[ ASSIGN assign-expression ...][ NO-ERROR ].
By default, the BUFFER-COPY statement copies all like-named fields from the source-buffer to the target-buffer. As with other assignments, if the data types and extents of the fields are not compatible, an error results. Fields in the source-buffer that have no like-named field in the target-buffer are not copied. Likewise, fields in the target-buffer that have no like-named field in the source-buffer are ignored. No error results from this mismatch of fields.
If you want to copy only certain fields from the source-buffer, you can do this in one of two ways:
*If you use the EXCEPT option followed by a list of field names, then those fields in the source-buffer are left out of the copy
*If you use the USING option followed by a list of field names, then only the fields in the list are copied
Thus, you can use either option depending on which one lets you specify a shorter list of fields for special handling. You might also want to consider future code maintenance in making this choice. If you use the EXCEPT option, then any fields that you might add in the future to the tables you're copying will automatically be picked up when you recompile the procedure. If you use the USING option they will not be. The option you choose depends on your reasons for including or excluding fields and on what you want to have happen if the buffer definitions change.
In addition to like-named fields, you can do any other kind of assignment from the source-buffer to the target-buffer using an ASSIGN statement. As with the ASSIGN statements you have seen in examples so far, this is basically a list of assignments with the target field on the left side of an equal sign and the source field on the right. You can also include a WHEN phrase in an assignment to define a logical expression that determines whether the assignment is done. For more information, see the section for the ASSIGN statement in the online help or in OpenEdge Development: ABL Reference.
As with other statements, the NO-ERROR keyword suppresses any error messages that might result from improper assignment and lets you query the ERROR-STATUS handle afterwards instead.