Unloadtable
Loops through a table field data set, copying values to host variables and, optionally, executing a block of code once for each row.
Examples--unloadtable statement:
Example 1:
This example processes the records in the data set within a database multi-statement transaction:
## begin transaction
## range of e is employee
## unloadtable empform employee
## (vname = ename, vage = age, vnum = eno,
## state = _state)
## {
/* undefined and unchanged are left alone */
/* new is appended */
if (state = 0) or
(state = 2) then
do nothing
else if (state = 1) then
## append employee (empnum = vnum, empname = vname,
## age = vage)
/* reflect changed data */
else if (state = 3) then
## replace e (empname = vname, age = vage)
## where e.empnum = vnum
/* deleted row */
else if (state = 4) then
## delete e where e.empnum = vnum
## }
## end transaction
## clear field employee
Example 2:
The following example adds the integer values of number and puts the average in a field called avgvalue:
rows = 0
sumvals = 0
## unloadtable statistics accumulator
## (vname = name, vnumber = number, record = _record)
## {
if (vname = "") then
## message "empty numeric identifier"
## sleep 2
## scroll statistics accumulator to record
## resume field accumulator /* break out of loop */
end if
rows = rows + 1
sumvals = sumvals + vnumber
## }
if (rows > 0) then
sumvals = sumvals/rows
end if
## putform statistics (avgvalue = sumval)
Example 3:
This example finds the first employee over the age of 60:
found = false
## unloadtable empform employee
## (vname = ename, vage = age, state = _state,
## record = _record)
## {
if (vage > 60) and (state < 4) then /* not deleted */
found = true
## endloop
end if
## }
if (found) then
process the specified record
end if
Example 4:
This example illustrates the use of null indicator variables with nullable columns:
## activate menuitem "printroster"
## {
## unloadtable empform employee
## (vname = ename, vage = age
## vspouse:indicator_var = spouse)
## {
/* do processing to create roster entry. */
## }
## }
Example 5:
This example checks the change variable of rows in a table field data set:
## activate menuitem "printorders"
## {
## unloadtable salesform saleslist
## (vorder = order, vitem = item)
## {
/* check if item ordered has changed. */
## inquire_frs row salesform saleslist
## (changed = change(item))
if (changed = 1) then
update the database
end if
process order and print out data
## }
## }
Last modified date: 08/14/2024