Insertrow and Arrays
To perform operations on the records of an array, use the insertrow statement or direct assignment to the records of the array.
When adding records to an array, the insertrow statement inserts a new record after the record whose index number you specify. This number refers only to the location of the record in the array, and has no relationship to the number the record might have if displayed in the window in a table field.
For example, to load an array with constant values, specify several insertrow statements:
insertrow array [0]
(coll = 1.0, col2 = 'Record1');
insertrow array [1]
(coll = 2.0, col2 = 'Record2');
insertrow array [2]
(coll = 3.0, col2 = 'Record3');
Instead of using the insertrow statement, load the data directly into each attribute of each array record:
array[1].coll = 1.0; array[1].col2 = 'Record1';
array[2].col2 = 2.0; array[2].col2 = 'Record2';
array[3].col3 = 3.0; array[3].col2 = 'Record3';
You must load the rows in sequence; you cannot have any empty rows. In the preceding example (for both the insertrow statements and the direct assignment), attempting to load data into array[5] without first loading array[4] results in a runtime error.
Setting the Row State
4GL accepts the word _state as a valid column identifier of type integer. You can set the table field row (or array record) _state (internal) through the following insertrow syntax:
insertrow tablefieldname |arrayname [ [ integer ] ]
[ ( _state = expression ) ]
The _state attribute of the new record is Unchanged unless you specify a value for it in the insertrow statement.
You can also set _state through a query to the database or through the unloadtable statement.
Whenever you specify a value for _state, it must be in the range 0 through 3 (for table fields), or 1 through 3 (for arrays). _State and _record are discussed in
Writing 4GL Statements.
Examples
Insert an empty row after the current row:
insertrow emptbl;
Insert a row after the third row in the table field, with a value of "new" in the status column:
insertrow emptbl[3] (status = 'new') ;
Insert a new record in an array and set _state to "new:"
insertrow emparray[5] (_state = 1)
The following statement opens up a new row immediately following row 4 in the table field partstbl.
insertrow partstbl[4];
The following statement inserts constant values into the third record of the array emparray.
insertrow emparray[2]
(col1 = 3, col2 = "the third record");
The following statement inserts a new row into the first (top) index of the array pricearr:
insertrow pricearr[0]
(name = 'bucket', cost = 20.00);
Last modified date: 08/28/2024