6. Working with Arrays, Table Fields, and Collections : Arrays : How You Can Manipulate Arrays : How You Can Specify an Array Row to be Deleted
 
Share this page                  
How You Can Specify an Array Row to be Deleted
The SetRowDeleted method sets the _RowState attribute of a specified row to RS_DELETED. Marking a row deleted is useful to allow the application to access the data in the deleted row before the data is lost.
For example, assume a user edits the data displayed in a table field, changing data in some rows and deleting a few rows. When finished, the user clicks the Save button. The event block associated with this button checks the _RowState of each row in table field's array and, based on the row state, performs the appropriate operation in the database.
The following code fragment illustrates such row checking:
on click menu.save_menu =
begin
  i = custtable.FirstRow;
  while i <= custtable.LastRow do
      if custtable[i]._rowstate = RS_DELETED then
          repeated delete from customer
          where acctno = :cust_table[i].acctno;
      elseif custtable[i]._rowstate = RS_NEW then
          repeated insert into customer ...
      elseif custtable[i]._rowstate =
          RS_CHANGED then repeated update
          customer...
      endif;
      i = i + 1;
  endwhile;
  commit;
end;
Note:  If the user had actually removed rows from the array, rather than marking them as deleted, the application would not be able to apply those deletions to the database.
The syntax for the SetRowDeleted method is:
integer = ArrayObject.SetRowDeleted(rownumber = integer)
rownumber = integer
(Required.) Identifies the row to be deleted
The effect of marking a row as deleted depends on the initial state of the row:
Original row state of RS_CHANGED or RS_UNCHANGED
Marking the row as deleted gives the row a non-positive sequence number in the array but does not remove it from the array. The first row deleted becomes row 0, the next row deleted becomes -1, and so on. If, for example, 10 rows were marked RS_DELETED, the FirstRow method would return ‑9.
After a row is marked as deleted, OpenROAD moves the rows that follow the deleted row down in the array's row sequence. For example, if you mark row 3 deleted, then the current row 4 becomes row 3.
Original row state of RS_NEW or RS_UNDEFINED
Marking the row as deleted actually removes the row from the array.
In all cases, if the array is displayed in a table field, the row is removed from the table field display.