Kbase 6094: How to copy field values from a record to another
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/05/1998 |
|
How to copy field values from a record to another
901214-cmb01
INTRODUCTION:
=============
This Technical Service Knowledgebase Entry will demonstrate how to
copy all fields from one record to another without defining an extra
buffer and without having to explicitly mention all of the field
names.
The trick is to use the screen buffer instead of using an extra record
buffer. When using the screen buffer, we can use "assign file-name"
to move all field values back to the new record in the file buffer.
WHY YOU WANT TO DO THIS:
========================
This method of copying a record has at least two advantages over the
traditional solution of defining a buffer and explicitly setting each
field. There is less coding required so you do not have to type all
field names, and it is easier to maintain.
On the other hand, there is a potential problem with this method. If
the record you want to copy contains data which is "wider" than the
corresponding field format, it will either truncate the date
(character fields), or fail to copy the record (decimal, integer, or
data fields).
PROCEDURAL APPROACH:
====================
/* Find the new customer you want to copy from */
FIND LAST customer.
/* Send the output to the null-device (to "nowhere") */
/* We don't want anything on the screen, only in the screen-buffer */
IF opsys = "unix" THEN OUTPUT TO "/dev
ull".
ELSE IF opsys = "dos" THEN OUTPUT TO "nul".
ELSE IF opsys = "vms" THEN OUTPUT TO "nl".
ELSE IF opsys = "btos" THEN OUTPUT TO "[nul]".
/* Copy all customer-data from file-buffer to screen-buffer */
DISPLAY customer.
/* Add one to the last cust-num in the screen-buffer */
DISPLAY cust-num + 1 @ cust-num.
/* Create a new customer */
CREATE customer.
/* Copy all customer-data from screen-buffer to the new customer */
ASSIGN customer.
OUTPUT CLOSE.
NOTE: If you are using more than one frame for the table, you have to
specify from which frame you want to assign the data, perhaps using
the DO WITH FRAME <frame-name> syntax or with the FRAME option of the
ASSIGN statement.
Since Progress 8.1A there is the BUFFER-COPY statement that can be
used for this same purpose.
Progress Software Technical Support Note # 6094