CopyTo method: Rowset class
Syntax
CopyTo(&DestRowset [, record_list])
Where record_list is a list of record names in the form:
[RECORD.source_recname1, RECORD.target_recname1
[, RECORD.source_recname2, RECORD.target_recname2]]. . .
Description
The CopyTo method copies from the rowset executing the method to the specified destination rowset, copying like-named record fields and subscrolls at corresponding levels.
The CopyTo method uses the current data in the rowset. This might be different from the original data values if the rowset was retrieved from the database and values in it have been changed either by an end-user or a PeopleCode program
If pairs of source and destination record names are given, these are used to pair up the records and subscrolls before checking for like-named record fields. Then, after copying the named records pairs, this method copies all identically named records.
Note:
This method does not work for Application Engine state records. If you don’t specify record_list, both the record name and the field name have to match exactly for data to be copied from one record field to another. If you specify record_list, after the records have been paired up, the field names have to match before any data is copied.
If the rowset you are copying from has the field level EditError, as well as the MessageNumber and MessageSetNumber properties set, these values are copied to the rowset you are copying to. For example, suppose you had an application message that had errors. Using the GetSubContractInstance function, these errors would be copied into the message object. From there, you could instantiate a message rowset, copy the message rowset into a work rowset, and use the work rowset to populate Component buffers. (After the field properties are set, the Record, Row, and Rowset properties IsEditError also get set.)
In order to copy all of the properties of the fields from the source rowset, the source and target scrolls must have exactly the same shape:
-
The names of the records in the source and target scrolls must be the same.
-
If there are subscrolls in the source scroll, then the same number of subscrolls must exist in the target scroll.
-
The names of the records in any source subscrolls and target subscrolls must be the same.
Parameters
| Parameter | Description |
|---|---|
|
&DestRowset |
Specify the rowset to be copied to. This Rowset object must have already been instantiated. |
|
SourceRecname |
Specify a record to be copied from, in the Rowset object being copied from. |
|
DestRecname |
Specify a record to be copied to, in the Rowset object to be copied to. |
Returns
None.
Example
If you set one rowset equal to another, you haven’t made a copy of the rowset. Instead, you have two variables pointing to the same data.
To make a clone of an existing rowset, that is, to make two distinct copies, you can do the following:
&RS2 = CreateRowset(&RS);
&RS.CopyTo(&RS2);
The following example copies data from one rowset object to another. Because no like-named records exist between the two rowsets, the record names are specified. Only the like-named fields are copied from one rowset to the other:
Local Rowset &RS1, &RS2;
Local String &EMPLID;
&RS1 = CreateRowset(RECORD.PERSONAL_DATA);
&RS2 = CreateRowset(RECORD.PER_VENDOR_DATA);
&EMPLID = "8001";
&RS1.Fill("WHERE EMPLID =: 1", &EMPLID);
&RS1.CopyTo(&RS2, RECORD.PERSONAL_DATA, RECORD.PER_VENDOR_DATA);
The following example copies data from a message into the Component buffers, then calls the page (using TransferPage) to redraw the page. You could do this to fill a page with message data that is in error, so that an end-user can make corrections to the message data. &WRK_ROWSET0 is the level zero rowset and &WRK_ROWSET1 is where the data is copied to.
/* Get the Message */
&MSG = GetSubContractInstance(&PUBID, &PUBNODE, &CHNLNAME, &MSGNAME, &SUBNAME);
/* Get the Message Rowset */
&MSG_ROWSET = &MSG.GetRowset();
/* Get Level 0 */
&WRK_ROWSET0 = GetLevel0();
/* Create Work rowset */
&WRK_ROWSET1 = GetLevel0()(1).GetRowset(SCROLL.EN_REVISION_TMP);
/* Populate Work Rowset */
&MSG_ROWSET.CopyTo(&WRK_ROWSET1, RECORD.EN_REVISION, RECORD.EN_REVISION_TMP);
SetNextPage("EN_REVISION_MSG");
TransferPage();