19. Using 4GL : Assigning Values to Fields and Variables : Direct Assignments
 
Share this page                  
Direct Assignments
A direct assignment statement assigns a value into a simple field in a form, a simple local or global variable, a column in a table field, or the attribute of a record or an array record attribute. The value assigned must have an Ingres data type. For example, you can place a literal value such as "Jones" in the character field Lastname with either of these assignment statements:
lastname := 'Jones'; 
lastname = 'Jones';
In the following example, the statement is illegal because the left- and right-hand sides of the assignment have incompatible types. Lastname is a character field while 35 is an integer.
lastname := 35; /* error! */
You can make simple assignments into a table field cell. The following statements place the specified values in the current row of the table field:
child.name := 'Steven';
child.age := 11;
Except for unloadtable loops, the current row is the row on which the cursor is positioned. A runtime error occurs if the cursor is not positioned with the table field.
The following statements assign the specified values to the second row in the child table field:
child[2].name := 'Sally';
child[2].age := 8;
Note that the integer expression "2" refers to a row in the table-field display in the window, not to a record in the underlying data set.
To make a direct assignment of values to record attributes, place the name of the record and attribute (in record.attribute format) on the left of the assignment statement. This example assigns the specified value to the name and salary attributes of the record employee:
employee.name := 'John' ;
employee.salary := '50000' ;
Assigning values to arrays is similar to assigning values to table fields. Place the name of the array, index, and attribute on the left of the assignment statement and the value on the right. Arrays differ from table fields in that, for arrays, the index is always required, except in an unloadtable loop.
This example assigns the specified value to the name and address attributes in the third record of the array named parent:
parent[3].name := 'Janet' ;
parent[3].address := 'New York' ;
The "3" in brackets is an integer expression that indicates the third record of the array.