Push method: Array class
Syntax
Push(paramlist)
Where paramlist is an arbitrary-length list of values in the form:
value1 [, value2] ...
Description
The Push method adds the values in paramlist onto the end of the array executing the method. If a value is not the correct dimension, it is flattened or promoted to the correct dimension first, then the resulting values are added to the end of the array.
Parameters
| Parameter | Description |
|---|---|
|
paramlist |
An arbitrary-length list of values, separated by commas. |
Returns
None.
Example
The following example loads an array with data from a database table.
Local array of record &MYARRAY;
Local SQL &SQL;
&I = 1;
&SQL = CreateSQL("Select(:1) from %Table(:1) where EMPLID like ‘8%’",⇒
&REC);
While &SQL.Fetch(&REC);
&MYARRAY.Push(CreateRecord(RECORD.PERSONAL_DATA));
&I = &I + 1;
&REC.CopyFieldsTo(&MYARRAY[&I]);
End-While;
Considerations Using Arrays With Object References
This method only adds an element to the end of an array. It does not clone or otherwise deep-copy the parameters. For example, if you are adding a reference to an object, Push just adds a reference to the object at the end of the array. This is similar to an assignment. It is not making a copy of the object. The following code snippet only puts a reference to the same record onto the end of the array.
While &SQL.Fetch(&Rec);
&MYARRAY.Push(&Rec);
...
End-While;
Even though the array is growing, all the elements point to the same record. You have only as many standalone record objects as you create. The following code snippet creates new standalone records, so each element in the array points to a new object:
local Record &FetchedRec = CreateRecord(Record.PERSONAL_DATA);
While &SQL.Fetch(&FetchedRec)
&MYARRAY.Push(&FetchedRec);
&FetchedRec = CreateRecord(Record.PERSONAL_DATA);
End-While;