I. EQUEL/FORMS Examples : Putrow
 
Share this page                  
Putrow
Updates values in a table field row.
Examples--putrow statement:
Example 1:
In this example, the PutCurrent operation places data in the table field row on which the cursor currently sits:
## activate menuitem "putcurrent"
## {
     /* put new information into the current row. */
##   putrow empform employee (age = 52, sal = vsal)
## }
Example 2:
In this example, the PutFirst operation puts data in the first displayed row of the table field:
## activate menuitem "putfirst"
## {
##   putrow empform employee 1 (sal = vsal)
## }
Example 3:
This example illustrates the use of the putrow statement within an unloadtable loop. As the employee table field is unloaded, the putrow statement marks the processed rows to prevent them from being reprocessed. The hidden column marked, specified as i1, is used for this purpose.
## activate menuitem "processrecords"
## {
##   unloadtable empform employee
##         (vname = ename, vage = age, vmarked = marked,
##         state = _state)
##  {
    /* process if new, unchanged or changed */
    if ((state = 1 or state = 2 or state = 3) and
       (vmarked = 0)) 
         then
              process the data
##            putrow empform employee (marked = 1)
         end if
##  }
## }
Example 4:
In this example, menu item UpdateOrder takes information about an order from simple fields and updates a table field row with the changed data:
## activate menuitem "updateorder"
## {
     /* get data from other fields */
##   getform sales (name:null_indicator = salesperson)
     /* update table field row */
##   putrow sales saleslog
##        (ordernumber = order,
##        salesperson = name:null_indicator)
## }
Example 5:
This example illustrates use of the null constant:
## activate menuitem "neworder"
## {
##   putrow sales saleslist (salesperson = null,
##                           ordernum = order)
## }
Example 6:
Process the records in the data set within a database multi-statement transaction. Reset the _state of any CHANGED or NEW rows so that a user can make further changes to the data set and see those changes correctly processed when this menu item is chosen again. Error handling is ignored.
## activate menuitem 'Save'
## {
  ## savepoint startupdate
  ## unloadtable empform employee
     (:ename = ename, :age = age, :eno = eno,
               :state = _state)
  ## {
     if (state = 0) then /* undefined is left alone */
          null
     else if (state = 1) then /* new is appended */
          ## insert into employee (eno, ename, age)
               values (:eno, :ename, :age)
          /* reset _state to UNCHANGED */
          ## putrow empform employee (_state = 2);
     else if (state = 2) then /* unchanged is left alone*/
          null
     else if (state = 3) then /* Reflect changed data */
          ## update employee 
               set ename = :ename, age = :age
               where eno = :eno
           /* reset _state to UNCHANGED */
          ## putrow empform employee (_state = 2)
     else if (state = 4) then /* deleted row */
          ## delete from employee 
               where eno = :eno
     end if
##   }
##   commit
##   clear field employee
## }