21. 4GL Statement Glossary : Loadtable
 
Share this page                  
Loadtable
Adds a row of data after the last row of a table field's dataset.
Syntax
loadtable tablefieldname
  (columnname = expression {, columnname =
    expression} )
  [with(display_attr(columnname)=attr_value
    {, display_attr(columnname)=attr_value})]
tablefieldname
Specifies the name of the table field into which the values are to be loaded
columnname
Specifies the name of a table field column into which values are to be loaded
expression
Specifies the value to be loaded into the specified column
display_attr
Specifies he display parameter to be assigned to the specified column. The display attribute can be reverse, blink, underline, intensity or color.
attr_value
Specifies the value for the display parameter. For color, the value is an integer from 0 to 7. For other display attributes, the value is 1 to turn the parameter on or 0 to turn the parameter off. For more details, see Set_forms.
Description
The loadtable statement loads values into a table field's data set. Each execution of loadtable appends one row to the end of the data set.
The data loaded is displayed until the table field's display window is full. Then newly loaded values continue to be added to the end of the data set. You can see these rows by scrolling to them.
The loadtable statement loads values directly into specified columns in the table field. The list of columnnames identifies the columns receiving values and the values they are to receive. You can specify displayed, invisible or hidden columns, but not derived columns. Use the with clause to specify display attributes for each column.
Any column not included in the list of columnnames receives a null if it is nullable or a default value (blank for character columns and 0 for numeric columns). When possible, values for derived columns are calculated (based on the specified columns and values) and loaded into the data set.
You cannot use the loadtable statement with arrays. The following example shows how to append a row to an array:
idx = callproc ArrayLastRow(arr) + 1;
arr[idx].name = 'Mike';
arr[idx].empno = '2345';
Using the _state Constant
If you use the _state constant for columnname, the value must evaluate to one of the following:
0—UNDEFINED
1—NEW
2—UNCHANGED
3—CHANGED
If you load a row and specify a state of UNDEFINED, you must not assign any values to any non-hidden columns for that row. You cannot load a row with a state of DELETED.
By default, if you do not assign an explicit row state to a loaded row, the new row has the state of UNCHANGED. The state changes to CHANGED when you or the application alter any of the row's values. Each column in the loaded row (except hidden columns) then has its change variable cleared (set to 0).
Example
Selects from the "emp" table the employee number ("eno") and employee name ("ename") of all employees whose employee numbers are less than 30. The selected rows are appended to the end of the table field "emptf" without overwriting the existing contents of the table field.
The example uses the local variables "eno_wk" and "ename_wk." These must be declared with the same data types as the corresponding columns in "emp" and "emptf."
select eno_wk = eno, ename_wk = ename
from emp
where eno <= 30
begin
  loadtable emptf (eno = eno_wk,
      ename = ename_wk);
end;