2. Language Elements : Variables : Dynamic Array Variables : How You Can Reference Dynamic Array Variables
 
Share this page                  
How You Can Reference Dynamic Array Variables
You can reference an array as a whole unit or you can reference the individual elements of the array—a single row, a single column, or a single cell.
By referencing the array itself, you can work with the entire set of objects as a unit. For example, you can pass the entire array as a parameter to a procedure or you can retrieve a group of rows from a database table into a single array. You can also get information about the array and manipulate the array.
To reference an array as a unit, use the array name. For example, assume that movies is the name of an array and that you want to pass this array to the movie_list frame. You could use the following statement:
callframe movie_list (mv_fld = movies);
By referencing an individual row, you can work with an individual object in the array. To reference an individual row, use the following syntax:
arrayname[n]
where arrayname is the name of the array in which the row resides and n is the number of the row. For example, to pass one of the rows from the movies array to a procedure:
callproc update_row (mv_row = movies[i]);
By referencing a column, you can work with one attribute across all the objects. The syntax is:
arrayname[*].columnname
where arrayname is the name of the array and columnname is the name of the column. References to array columns are most commonly used to detect events, such as Entry or Exit events, on the column when the array is displayed in a table field, for example:
on entry movies[*].title...
To reference an individual element of an array, use the following syntax:
arrayname[n].columnname
where arrayname is the name of the array, n is the number of the row, and columnname is the name of the column.
An individual element of an array can be a reference variable or an array. This means that arrays can contain nested objects or arrays. You can also reference the individual elements of these nested objects or arrays in your 4GL code. For a nested object, the syntax is:
arrayname[n].nestedobject.attribute
where arrayname is the name of the object, n is the number of the row, nestedobject is the name of the nested object, and attribute is any attribute of that nested object.
For a nested array, the syntax is:
arrayname[n].nestedarrayname[x].attribute
where arrayname is the name of the outer array, n is the row number in that array, nestedarrayname is the name of the nested array, x is the number of the row within the nested array, and attribute is any attribute of the nested array.