INITIALIZE

 

Variable List

LIKE Keyword

TO NULL Clause

 

INITIALIZE statement is used to assign initial values to program variables. It can also assign a NULL value.

 

 

Element

Description

Variable List

A list of variables of simple data types, RECORD data type or array elements separated by comas

Column list

A list of database columns with table qualifiers, if necessary, separated by comas

 

Any variable declared with the help of the DEFINE statement has storage space allocated to it. The value assigned to a variable occupies that space. The INITIALIZE can be used with:

 

 

Variable List

 

Variable list can include one or more of the following variable types separated by comas:

 

 

LIKE Keyword

 

LIKE keyword in the INITIALIZE statement is used to specify the default values from syscolval columns. It requires the default database to be specified, thus the DATABASE keyword must appear before the first program block of the program module where you use the INITIALIZE statement with the LIKE clause.

 

The variables specified in the variable list must match the database columns specified in the column list in order, number and data types. A column must be prefixed with the name of its table.

 

INITIALIZE first_v, second_v

      LIKE my_table.col1, my_table.col2

 

If you use the table.* notation, you will assign the default values of every column of a table to the specified variables. The example below assigns the values of all the columns of a table to all the members of a record:

 

INITIALIZE my_record.* LIKE my_table.*

 

In an ANSI-compliant database you must specify not only the table name but also its owner, for the tables that are not owned by the current user. In the example below, the third column belongs to the current user, so the owner table qualifier is omitted:

 

INITIALIZE first_v, second_v, third_v

      LIKE j_smith.table1.col1, t_brown.table2.col5, table3.col7

 

You can include the owner table qualifier in a non ANSI-compliant database, but it is not obligatory. However, an incorrect owner prefix will produce an error.

 

The default values of columns are retrieved from the syscolval table, any changes in this table are reflected in a program (i.e. in the INITIALIZE statement), only if they are made before the program has been compiled. To apply the changes made after that, you must recompile the program. If a column has no default value, NULL value is assigned to an initialized variable.

 

You cannot use the LIKE keyword to assign values to the variables of large data types (BYTE and TEXT). They can be assigned only NULL values.

 

 

 

TO NULL Clause

 

TO NULL clause is used to assign NULL values to variables. The examples below initialize the variables and all record members to NULL:

 

INITIALIZE first_v, second_v, third_v TO NULL

INITIALIZE my_rec.* TO NULL

 

The variables are usually initialized to NULL due to such reasons:

 

In order to optimize performance, you may want to limit the use of the INITIALIZE statement with the TO NULL clause.