Specializing primitive types as DataItem parts

A DataItem part specializes a primitive data type by assigning it a name and optionally limiting the values that can be assigned to it. Defining a DataItem part reserves no storage; only when you declare a variable based on that DataItem part is storage reserved.

As with a Record, you define a DataItem outside of any other part. This automatically places the DataItem definition in package scope.

The properties available in a DataItem part include all field-level properties that are valid in any context. Consider, for example, a DataItem part that represents a US Social Security Number, an ID of nine (and only nine) digits. In some cases the ID is associated with a relational-database column named SSN:
  DataItem IDNumber CHAR(9) 
  {
    minInput = 9,         // requires 9 input characters
    isDecimalDigit = yes, // requires digits
    column = "SSN"    // is related to a column
  }
  end
Use the following syntax to declare an IDNumber variable:
  mySSN IDNumber;

You can declare that variable in a composite part such as a Record part or directly in a logic part such as a Program. In every case, the part type determines whether a given property is used.

In the current example, the column property is used only if the variable is declared in a record that is stereotyped for use with a relational database. The two validation properties are used only if the variable is declared in a user interface part.

You can use a data item variable anywhere that you can use a variable based on the same primitive data type as the data item. In other words, you can use mySSN from the previous example anywhere that you can use any other CHAR(9) variable.

Each primitive variable has a series of properties, whether by default or as specified in either the variable declaration or the DataItem part definition. Most of these properties are related to building a user interface; for more information, refer to the specific UI technology.


Feedback