Value and reference types

Value types are the basis of memory areas that contain business values. Reference types are the basis of data areas that reference business values. When you are copying data to or from a variable, you sometimes need to know the low-level details.

Consider the following declarations:
// variable declaration
NumberOfCars INT;

// constant declaration
const MINIMUMNUMBER INT = 2;

The type is each case is INT, which is a value type. The first statement declares a value variable, the second declares a value constant. In either case, the term instance refers to the value in the memory area itself.

For a second example, you might declare a list of five integers by coding a statement like one of these:
// variable declaration
NumberOfVehicles INT[5];

// constant declaration
const MINIMUMNUMBERS INT[5] = [1,2,3,4,5];

The type in this case is INT List or INT[], which is a reference type. The first statement declares a reference variable, which means that you can assign a different list to NumberOfVehicles in a later assignment. Incidentally, you can also change the values inside the list and can change the number of elements.

The second statement declares a reference constant, which means that you cannot assign a different list to MINIMUMNUMBERS in a later assignment. However, even in this case, you can alter the values inside the list and can change the number of elements.

The behavior is consistent because each declaration in the second example identifies a memory area that contains an address of a second memory area. The constant is only constant in the sense that the area identified as MINIMUMNUMBERS must always contain the same address, which refers to the same list. The following, subsequent assignment is not valid even though the values are the same:
// An invalid assignment
MINIMUMNUMBERS = [1,2,3,4,5];  

In relation to a reference variable or constant, the term instance refers to the value in the secondary memory area; that is, in the memory area to which the variable or constant refers.

Some simple types are expressed with parameters. For example, DECIMAL is a numeric type and can be restricted by parameters that define a second type such as DECIMAL(4).

With one exception, the following rule applies: If a simple type can be expressed with parameters, the non-parameterized type such as DECIMAL is a reference type, and the parameterized type such as DECIMAL(4) is a value type. The one exception is STRING and its parameterized equivalent: Both STRING and STRING(4) are reference types.

A variation in the assignment rules described earlier is in effect for simple-type fields. For details, see “Boxing and unboxing conversions.”