Reference variables and NIL in EGL

A parameter or variable is an area of memory. In some cases, the variable contains the business data of interest; a particular name or employee ID, for example. In other cases, the variable is a reference variable, which contains a memory address that is used to access the business data at run time.

A reference variable in EGL is based on one of the following parts, each of which is also called a reference type:

Except for Service and Interface parts, you do not define any of the previously mentioned parts, which are predefined by EGL.

Implications are as follows:
Initialization
When you declare a reference variable, EGL usually initializes the variable to the value NIL, which indicates that the variable does not point to any business data. In the following cases, the value NIL is not the initial value:
  • The variable is based on a part that includes a field initialized at definition time; or
  • The variable declaration includes a set-value block.

In the cases just mentioned, the variable refers to an area of memory that is created when the variable is declared.

When you declare an array of reference variables (for example, MenuItem[3]), the preceding rules also apply to each element in the array.

In assignment statements
After you assign a reference variable to another reference variable, the source and target each contain a value that is used to access the same area of memory. You can assign a reference variable only to another reference variable that is based on the same part, and in the case of an interface or service part, a part defined in one package is not the same as a part defined in another package, even if the part names are identical.
Note: When you assign a non-reference variable to another non-reference variable, the situation is different:
  • The source and target each contain a copy of the same business data. If a non-reference source variable in an assignment statement contains a specific employee ID, for example, the statement causes the target variable to contain that ID as well.
  • The variables may be of different types, as described in Assignment compatibility.
In comparisons
The operator that tests for equality (==) and inequality (!=) are valid for comparing reference variables. The comparison is based on the area of memory to which the variables refer. If two variables refer to different areas of memory, the two variables are not equal even if the business data is identical.
In function invocations
You can pass a reference variable only to a parameter of the same type; and in the case of an interface or service part, a part defined in one package is not the same as a part defined in another package, even if the part names are identical. However, you can pass a reference variable to a service function only if the parameter is of the same type as the argument and only if the invocation is local; specifically, only if local is the value of the complex property @EGLBinding, field commType.

The function always receives a copy of the variable being passed:
  • Assigning a different value to the data referenced by the parameter (for example, changing the color of a console field) changes the data that is available in the invoking function
  • However, using the parameter on the left side of an assignment statement in the invoked function has no effect on the invoking function. After the assignment, the parameter refers to the same area of memory as the area referenced by the variable on the right side of the assignment statement, but the argument in the invoking function is unaffected by that assignment.

The parameter modifiers IN, OUT, and INOUT are not valid for parameters of a reference type.

Any reference type is valid as a return type, which means that a copy of an address is returned to the invoking function at run time. Even if the reference type is declared as a local variable in the invoked function, the business data (and an area of memory to hold that data) is retained in the invoking function.

In calls to programs
You cannot pass a reference variable to another program.
In PageHandlers
You cannot pass a reference variable to the onPageLoad function in a PageHandler; nor can you place a reference variable in (or retrieve a reference variable from) the session or request object.

Related concepts

Related reference
Reference compatibility in EGL

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.