Null Values

A Null value means that the value of a field, variable or parameter is undefined. Variables and parameters are implicitly initialized to Null when they are declared. For String or Struct data types, Uniface provides some special handling.

For string variables, Null values are interpreted as an empty string (""). For Struct variables, NULL is interpreted as a collection of references to zero Structs.

Uniface implicitly converts the data type whenever necessary, for example, when assignments are made between non-matching data types, so the way Null values are interpreted can change.

For example, Null fields are saved into XML streams as empty elements. This means that a null field is indistinguishable from an empty string. When an empty element is loaded into a numeric field it is converted into a zero numeric value.

Example: Assigning Values to Struct Members

The following example assigns variables to Struct members and shows the effect that Null values can have on the Struct.

variables
  any    vAny               ; Implicitly initialized to NULL
  struct vStruct1, vStruct2 ; Implicitly initialized to NULL, but interpreted callout 1
  string vString            ; Implicitly initialized to NULL. but interpreted as ""
endvariables
  vStruct1->x = vAny        callout 2
  vStruct1->y = ""          callout 3
  vStruct1->z = vString     callout 4
  vStruct1->x = vStruct2    callout 5 
  vStruct1->y = vStruct2->z callout 6
  1.  For Struct variables, NULL is interpreted as or a collection of references to zero Structs.
  2.  vStruct1 is implicitly initialized to an empty Struct, and now gets one member named x, whose value is NULL. This is because the value of the vAny variable is NULL.
  3.  Another member, named y, is added to the Struct. Its value is also NULL because an empty Struct member is initialized to NULL
  4.  Another member, named z, is added to the Struct. Although the real value is NULL, vString is a string variable, so the value is an empty string (a String with zero length).
  5.  vStruct1 no longer has any members named x because x has been replaced by the contents of vStruct2. Since it is a struct with a NULL value, it is interpreted as being a list of zero references to Structs.
  6.  vStruct1 no longer has members named y either. Because vStruct2 has zero members named z, vStruct1 now also has zero members at the target y.

Related Topics