Initialize Statement—Initialize a Form
This statement performs any necessary initialization on the form.
Syntax
initialize [(fieldname = value
{, fieldname = value})]
[begin
initialization code;
end]
Description
The initialize statement lets you transfer data into the form at the start of a display loop and perform any necessary initial operations for the form. This statement is executed when the display loop begins, before the form actually appears on screen.
The list of fieldnames identifies the fields into which values are assigned. The fields listed must be simple fields. (You can transfer data into table field columns by means of the loadtable, insertrow, and putrow statements.) You can specify fieldname using a quoted or unquoted character string or a program variable. Similarly, value can be either a literal or a variable. A field and the value assigned to it must have compatible data types. (See your host language companion guide for information about compatible data types.)
There are two ways to insert a null into a field. First, you can specify value as the key word null. This method assigns a null to the field whenever the statement executes. The alternate, and more flexible method, uses an indicator variable. Using an indicator variable allows the user or program to decide at run time whether to place a null in the field.
An indicator variable is a two-byte integer variable associated with the variable used to assign values into the field. It is specified using the syntax:
initialize (fieldname = var:indicator_var)
You can only use an indicator variable when you use a variable for value. Also, you must have previously declared the indicator variable in a host variable declaration section.
When an indicator variable is set to -1, any value in its associated variable is ignored and a null is assigned to the specified field. You must set the indicator variable before executing the initialize statement and the receiving field must be nullable. See your host language companion guide for a complete description of the use of indicator variables.
If you include the optional begin/end block of code, you cannot place any other statements or program comment lines between the initialize statement and the block. However, the block itself can contain any host language or embedded SQL statement, as well as comment lines.
When used, you must put the initialize statement in a display block. Although not required, the initialize statement is often useful as a way to mark the start of the display loop.
Examples—initialize statement:
Example 1:
Place data from program variables into a form at the start of its display.
exec frs initialize (ename = :namevar,
sal = :salvar);
Example 2:
Place data in the form and display a message.
exec frs initialize (ename = 'Sally',
sal = 30000.00);
exec frs begin;
exec frs message 'You can begin editing data.';
exec frs sleep 2;
exec frs end;
Example 3:
Place a null into a field.
exec frs initialize (spouse = null);
Example 4:
Place a value into a nullable field.
exec frs initialize
(spouse = :spouse_var:indicator_var);