DOCUMENT # 777
     ===========================================================================
     UPDATE IN AN EEP
     ===========================================================================
     PRODUCT:  R:BASE                           VERSION:  4.5+ or Higher
     ===========================================================================
     CATALOG:  Forms, Reports & Labels          AREA   :  Forms
     ===========================================================================
 
 
     Many users want to use an UPDATE command in an EEP to conditionally change
 
     data. Often it is desired to change data on the same row the user is 
     editing. You may want to change data in fields that are not located on the
 
     form based on data users enter into the form. This isn't a straightforward
 
     operation.
 
     R:BASE retrieves an entire row into memory when using a form. Even though 
 
     you UPDATE data that is not located on the form, when the row is saved to 
 
     the table, the entire row is written back, right over the top of the 
     updated data. There is a way to make this work, however. You need to not 
     only save the row before doing the UPDATE but you need to clear the 
     "changed" flag.
 
     When editing data, R:BASE only rewrites the row to the table if a column 
     value has been changed. If a column value has been changed (i.e. a 
     located column has been typed into), R:BASE sets what is called the 
     "changed" flag. That indicates that the row data has changed. When the 
     "changed" flag is set, R:BASE re-evaluates expressions and saves the 
     changed data back to the table.
 
     The EEP command, SAVEROW, does not reset the "changed" flag. It is sort 
     of like doing an incremental save with Edit. It is not the same as the 
     option Save changes on the Edit menu. Save changes on the Edit menu 
     actually does a Save and then a Next -- it saves the current row and 
     then it gets the next row. The next row action clears the "changed" flag.
 
     To UPDATE the same row being edited, you need to do both a SAVEROW and a 
     NEXTROW in an EEP. This example EEP leaves you on the same row in the 
     form by doing a PREVROW after the NEXTROW. 
 
     Note that this procedure is for forms used with the Edit data option only.
 
 
     *(CHANGEIT.EEP)
     SET ERROR VAR verr
     SET MESSAGE OFF
 
     SAVEROW
     SET VAR vnewtitle = 'newvalue'
     SET VAR vsave_emp=.vempid
     NEXTROW
     IF VERR = 0 THEN
       UPDATE employee SET emptitle = .vnewtitle +
         WHERE empid = .vsave_emp
       PREVROW
     ELSE
       UPDATE employee SET emptitle = .vnewtitle +
         WHERE empid = .vsave_emp
     ENDIF
      SET MESSAGE ON
     SET ERROR VAR OFF
 
     The identifying row ID is passed to the EEP through a variables. You can 
     use a form expression, vempid = empid, to do this. The R:BASE error 
     variable is used to determine if you are on the last row. If you are on 
     the last row, the NEXTROW command returns an error. In that case, you 
     only do the UPDATE, not the PREVROW. Because the NEXTROW evaluates form 
     expressions again, the identifying row ID value is saved to a second 
     variable, vsave_emp. This second variable is actually used in the UPDATE 
     command.