CreateRecord function
Syntax
CreateRecord(Record.recname)
Description
Use the CreateRecord function to create a standalone record definition and its component set of field objects. The specified record must have been defined previously, that is, it must have a record definition. However, if you are calling this function from PeopleCode associated with a page, the record does not have to be included on the current page.
The record and field objects created by this function are accessible only within PeopleCode. They can be used with any of the record and field object methods and properties. The record and field objects are automatically deleted when there are no remaining references to them stored in any variables.
The fields created by this function are initialized to null values. Default processing is not performed. No data associated with the record definition’s SQL table is brought in: only the record definition.
You can select into a record object created this way using the SelectByKey record class method. You can also select into it using the SQLExec function.
Parameters
| Parameter | Description |
|---|---|
|
Record. recname |
Specify a record definition that already exists. |
Returns
This function returns a record object that references a new record buffer and set of fields.
Example
Local Record &REC2;
&REC2 = CreateRecord(RECORD.OPC_METH);
In the following example, a free-standing record is created (&PSBATREPREQRES). Values are assigned to the fields associated with the record. Then a second record is created (&PUBHDR), and the values from the first record are used to populate the second record.
&PSBATREPREQRES = CreateRecord(RECORD.PSBATREPREQRES);
&PSBATREPREQRES.BATREPID.Value = &BATREPID;
&PSBATREPREQRES.PUBID.Value = &MSG.Pubid;
&PSBATREPREQRES.CHNLNAME.Value = &MSG.ChannelName;
&PSBATREPREQRES.PUBNODE.Value = &MSG.PubNodeName;
&PSBATREPREQRES.MSGNAME.Value = &MSG.Name;
&PUBHDR = CreateRecord(RECORD.PSAPMSGPUBHDR);
&PSBATREPREQRES.CopyFieldsTo(&PUBHDR);
To create a PeopleCode record object for a record whose name is unknown when the PeopleCode is written, do the following.
Suppose a record name is in the PeopleCode variable &RECNAME. Use the @ operator to convert the string to a component name. The following code creates a corresponding record object:
&RECNAME = "RECORD." | Upper(&RECNAME);
&REC = CreateRecord(@ &RECNAME);
The following example uses SQLExec to select into a record object, based on the effective date.
Local Record &DST;
&DST = CreateRecord(RECORD.DST_CODE_TBL);
&DST.SETID.Value = GetSetId(FIELD.BUSINESS_UNIT, DRAFT_BU, RECORD.DST_CODE_TYPE, "");
&DST.DST_ID.Value = DST_ID_AR;
SQLExec("%SelectByKeyEffDt(:1,:2)", &DST, %Date, &DST);
/* do further processing using record methods and properties */