Null values and the nullable type

Technically a null value is a reference (called a pointer in some languages) to an empty area of memory. Reference variables (variables that contain an address for data rather than the data itself) are always nullable, which means they are automatically capable of having a null value. What makes the idea complex is that you can make value variables nullable as well.

The main advantage you get from making a variable nullable is the ability to test it to see if it has a useful value, as in the following example:
if (myCustomer != null)
	get myCustomer;
end

Certain functions in the system libraries dateTimeLib and strLib, such as dateTimeLib.timeValue(), can return null values, either because you pass them a null value, or because the information you request does not exist.

To indicate that a value variable is nullable, append a question mark (?) to the type when you declare it. This works in most of the type specifications that EGL permits, as in the following example:
myNullableInt INT?;
You can use the word "null" in any of the following:
You cannot use the word "null" in any of the following:

Making a variable nullable gives it a flag that says whether the variable is null or not. Setting the variable to null sets this flag.

Note that a record is a value variable; if the record is nullable and set to null, you can still access fields within that record. However, you cannot use a null record in an I/O statement that outputs data from the record; this will cause EGL to throw a NullValueException. Similarly, the I/O statements that put data into a record will set its null status to false.

Nullable variables are assignment compatible with variables that are not nullable, provided their base types are assignment compatible. Nullable variables are reference compatible only with other nullable variables that have the exact same base type. For more information, see Assignment to or from nullable types.

In regard to services, sending a null value as an argument in a remote service call means that no data is sent. Because the receiving parameter is nullable, the receiving function creates a new, uninitialized value for the missing data then passes it to the requested service function.

Examples

myArrayNullInts INT?[];

Function getCustomer (custNum INT?) returns (CHAR(25)?)
   ...
end

myCustomer CustomerRecord?;

Compatibility considerations

Table 1. Compatibility considerations
Platform Issue
JavaScript generation The following types are supported: ANY, BIGINT, BIN (but only in the absence of decimal places), Boolean, DataItem, DATE, DECIMAL, Delegate, Dictionary, FLOAT, INT, NUM, NUMBER, SMALLFLOAT, SMALLINT, STRING (but only in the absence of a size limit) , TIME, TIMESTAMP, NUM, MONEY, Service parts, Interface parts, External types (stereotype JavaScript), arrays of supported types, and non-structured Basic, Exception, and SQL Record parts.

The following types are not supported: ArrayDictionary, BIN (with decimal places), BLOB, CHAR, CLOB, DBCHAR, HEX, INTERVAL, MBCHAR, NUMC, STRING (with a size limit), PACF, UNICODE, and structured Record parts.