Using Initialize and Declare Statements
Use declaration statements during the initialization operation to declare local variables or hidden columns in a table field on a form. Local variables and hidden columns are useful for computation and holding temporary data that the user does not see or change.
Two types of declaration lists are associated with the initialize statement. The following syntax shows these lists:
initialize
[( localvariable | tablename.hiddencolname =
typedeclaration {, localvariable |
tablename.hiddencolname = typedeclaration} ) ] =
[declare localvariable | tablename.hiddencolname =
typedeclaration {,localvariable |
tablename.hiddencolname = typedeclaration }]
begin
/* statements * /
end
• Local variables and hidden columns declared within the parentheses following the initialize keyword can be parameters to the frame. They can receive values from other frames through call parameter lists by keyword.
• Local variables and hidden columns declared in the declare section cannot receive values from other frames through call parameter lists.
A 4GL local variable can be of any data type. This includes simple Ingres data types, records derived from form, table field, or table definitions, record types defined to the application, and arrays of records.
For clarity, place all local variables in the declare section to distinguish them from passed parameters. The following example establishes the variable i as an array index that is strictly local to the current frame:
initialize () =
declare
i = smallint not null
begin
i = 1;
end
The example below declares the simple local variable total and sets its initial value to 0. Total is not a parameter.
initialize () =
declare
total = integer
begin
total := 0;
end
The following example declares several local variables and hidden columns:
initialize () =
declare
idnum = integer with null,
idname = varchar(10),
emptbl.empnum = smallint,
emptbl.empsal = float with null,
projtbl.projid = varchar(6)
begin
idnum := NULL;
idname := 'none';
end
In the example above, the current form contains table fields emptbl and projtbl. This initialization declares two local variables (idnum and idname) and initializes them with values. It also declares two hidden columns in the table field emptbl (empnum and empsal), and one hidden column in the table field projtbl. The local variables are set to the initial values "null" and "none."
Last modified date: 08/14/2024