6. Working with Arrays, Table Fields, and Collections : Arrays : How You Can Manipulate Arrays : How You Can Use the _RowState Attribute
 
Share this page                  
How You Can Use the _RowState Attribute
To determine changes made directly to an array by a user editing a table field, you can use the _RowState attribute for each row in an array. This attribute contains information about the state of each row, indicating the last action performed on the row by the user or by the SetRowDeleted method. Changes made to an existing row by a 4GL script (except any changes resulting from the execution of the SetRowDeleted method) do not affect this attribute.
There are five valid row states:
RS_UNDEFINED
Indicates that:
A row was automatically added to the end of an array when a user, in a table field, set the input focus to the row just beyond the last row or used the down arrow key to move past the last row.
A user selected the Insert Before Current Row operation from a table field's default control button. A row whose state is RS_UNDEFINED cannot change to a state of RS_DELETED. When these rows are deleted by any means, they disappear from the array.
RS_NEW
Occurs when a user types in or otherwise changes an undefined (RS_UNDEFINED) row.
A row whose state is RS_NEW cannot change to a state of RS_DELETED. When these rows are deleted by any means, they disappear from the array.
RS_UNCHANGED
Indicates a row that was added to the array by a 4GL script (by the InsertRow method or assignment statement) and has not yet been changed by the user.
RS_CHANGED
Occurs when a user makes a change, other than a deletion, to an RS_UNCHANGED row. If the user changes the data and then sets it back to its original value, the row's state remains RS_CHANGED.
RS_DELETED
Indicates a row that was initially RS_UNCHANGED or RS_CHANGED and then was marked deleted, either by the program (using the SetRowDeleted method) or by a user (using the table field control button's Delete Current Row or Delete All Rows operation).
A row that has the state RS_DELETED remains in the array with a non-positive row number.
You can force a row to reflect a different state than would occur by default by directly assigning a value to the _RowState attribute. For example, assume a frame remains open after the user clicks the Save button. This frame lets the user continue making changes to values in a table field after saving existing changes. To prevent the same changes from being written to the database the next time the user clicks the Save button, you can set the state of all rows back to RS_UNCHANGED. The following code fragment checks the row state of every row in the custtable array, makes appropriate changes to the database, and resets the value of all row states to RS_CHANGED:
for i = custtable.FirstRow to 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;
  commit;
  /*Reset rowstate to prevent handling this row
  ** again on next Save unless data changes
  ** again. */
  custtable[i]._RowState = RS_UNCHANGED;
endfor;