19. Using 4GL : Local Variables and Hidden Columns : Complex Local Variable Definitions
 
Share this page                  
Complex Local Variable Definitions
You can define complex local variables (records or arrays) that are either:
Of a global record type that you create in ABF or Vision, or
Based on an existing form, table field, or table.
To define these complex local variables, use one of the following formats:
variable = record_type_name
variable = type of form form_name
variable = type of table field form_name.table_field_name
variable = type of table table_name
variable = array of record_type_name
variable = array of type of form form_name
variable = array of type of table field
form_name.table_field_name
variable = array of type of table table_name
In form and table field record types, only visible columns or fields (defined through the ABF FormEdit operation for the form or table field) are used in the record type definition. Local variables or hidden columns (defined in 4GL) are not included. The form or table field on which a record type or array is based need not be used in the current frame, or even in the current application.
Form, table field, and table-based record and array definitions reflect the object at the time the frame or procedure that uses them is compiled. The record or array definition is thus dependent on the form or table. ABF marks the 4GL code for recompilation whenever the form or table changes.
Each of these rules is discussed in the following sections.
Complex Local Variables Based on Record Types
Declare a variable of a complex type as you do a simple local variable, by stating its name and data type. You can base local variables on record types. A local variable defined as a record type or an array references the data in the record or records. For a variable of a record type, use this syntax:
variable = record_type_name
Record_type_name is a record type defined for the application through ABF. A record type defined for an application overrides any Ingres data type whenever the two conflict.
In the following example, new_emp is declared as a variable of the record type emp_record:
new_emp = emp_record
Form-based Record Types
4GL recognizes form record types. This record type corresponds to a form you specify; the attributes of the form record type have the same names and data types as the fields of the form. Table fields on the form are included as array attributes of the form record type. Use the following syntax to declare a variable based on a form:
variable type of form form_name
Form_name is the name of an existing form. You can base form record types on any form available to the application owner in the application database. They are not restricted to forms in the current application.
In the following example, empnote_record is a record based on the form Emp:
empnote_record = type of form emp
Table-field Based Record Types
In the table field record type, the attributes of a record type are given the same names and data types as the columns of the table field you specify:
variable type of table field
  [form_name.]table_field_name
Table_field_name is the name of an existing table field on the form_name form. Table field-based record types are based on any table field on a form. They are not restricted to table fields in the current form. The table field must be available to the application owner and be in the application database.
The following example creates a variable, new_emp, with a record structure the same as the table field emptable.
new_emp = type of table field empform.emptable
In form and table field record types, only columns or fields defined in VIFRED for the form or table field are used in the record type definition. Local variables or hidden columns (defined in 4GL) are not included.
Table-based Record Types
In a table record type, you declare a record type that corresponds to a database table. Each attribute of the record type corresponds to a column (attribute) of the database table and has the same name and data type. Use the following declaration syntax:
variable = type of table table_name
Table_name is the name of an existing database table.
The following example creates a variable, emp_record, with a record structure the same as the Employee table.
emp_record = type of table employee
Arrays Based on Record Types
You can base array declarations on other complex data types. Use this syntax to base an array variable on a record type:
variable = array of record_type
Record_type is the name of a record type. This syntax cannot be used for hidden column definitions.
The following example creates an array variable, emp_retire, with a structure the same as the record type emp_record.
emp_retire = array of emp_record
You cannot define explicit multidimensional arrays in 4GL. To nest arrays, define an array of a record type that includes an array of another record type.
Arrays Based on Forms, Table Fields, and Tables
The syntax for creating arrays based on forms, table fields, and tables is similar to the syntax for creating record types based on these elements. The following examples show the syntax for basing an array on each of these types.
Use this syntax to base an array on a form:
variable = array of type of form form_name
The following example creates an array variable, emp_info, based on the form Employee.
emp_info = array of type of form employee
Use this syntax to base an array on a table field:
variable = array of type of table field
  [form_name.]table_field
The following example creates an array variable, emp_name, based on the table field Empname in the Employee form.
emp_name = array of type of table field employee.empname
Use this syntax to base an array on a table:
variable = array of type of table  table_name
The following example creates an array variable, emp_arr, based on the Employee table.
emp_arr = array of type of table employee