Caché supports a number of data types for variables, where each data type is itself a class. Each data type class represents a specific literal type, such as a string or integer. These data type classes determine the behavior of both object properties and fields in relational tables. Caché also allows you to create your own data types.
Data type classes provide the following features:
Data type classes differ from other classes in a number of ways:
Available Types
Caché provides a library of the most common data types including strings, integer, floats, timestamps and so on. These are:
Caché Data Type Classes
Class Name Holds Analogous SQL Type(s)
%Binary binary data BINARY, BINARY VARYING, RAW, VBINARY
%Boolean a boolean value N/A
%Currency a currency value MONEY, SMALLMONEY
%Date a date DATE
%Float a floating point value DOUBLE, DOUBLE PRECISION, FLOAT, REAL
%Integer an integer BIT, INT, INTEGER, SMALLINT, TINYINT
%List data in $List format N/A
%Name a name in the form “ Lastname,Firstname” N/A
%Numeric a numeric values of varying precision DEC, DECIMAL, NUMBER, NUMERIC
%Status an error status code N/A
%String a string CHAR, CHAR VARYING, CHARACTER, CHARACTER VARYING, NATIONAL CHAR, NATIONAL CHAR VARYING, NATIONAL CHARACTER, NATIONAL CHARACTER VARYING, NATIONAL VARCHAR, NCHAR, NVARCHAR, VARCHAR, VARCHAR2
%Time a time value TIME
%TimeStamp a value for a time and date TIMESTAMP
Operation
This section describes the basic features and functionality of Caché data types.
Using Data Types in Classes
The principal function of data type classes is for specifying the types of properties within a class. The basic definition format is:
Property City As %String;
Because data types are part of the %Library package, you can simply call them without explicitly mentioning the package name.
Validation Functionality
Any property using a system data type (or a data type derived from a system data type) supports data validation through a generated method associated with the property. The validation method has a name of the form PropertyNameIsValidDT; for instance, an Age property of type %Integer has an associated AgeIsValidDT method. The method checks the validity of a value specified for the property.
Parameters
Data type classes support various parameters. These perform various actions and vary from data type to data type. These parameters include:
The supported parameters for each of the system data types are:
Supported Parameters for System Data Type Classes
Data Type Class Supported Parameters
%Binary MAXLEN, MINLEN
%Boolean  
%Currency DISPLAYLIST, FORMAT, MAXVAL, MINVAL, VALUELIST
%Date DISPLAYLIST, FORMAT, MAXVAL, MINVAL, VALUELIST
%Float DISPLAYLIST, FORMAT, MAXVAL, MINVAL, SCALE, VALUELIST, XSDTYPE
%Integer DISPLAYLIST, FORMAT, MAXVAL, MINVAL, VALUELIST, XSDTYPE
%List ODBCDELIMITER
%Name COLLATION, INDEXSUBSCRIPTS, MAXLEN, XSDTYPE
%Numeric DISPLAYLIST, FORMAT, MAXVAL, MINVAL, SCALE, VALUELIST
%Status  
%String COLLATION, DISPLAYLIST, MAXLEN, MINLEN, PATTERN, TRUNCATE, VALUELIST, XSDTYPE
%Time DISPLAYLIST, FORMAT, MAXVAL, MINVAL, VALUELIST
%TimeStamp DISPLAYLIST, MAXVAL, MINVAL, VALUELIST
Keywords
To provide interoperability with client systems, data type classes include the following class keywords:
CLIENTDATATYPE
To use Caché data with any client system (such as Java or ActiveX), the data needs to be in a form that the client system can understand. To do this, Caché provides the CLIENTDATATYPE class keyword, which specifies format information for how Caché projects a property to the client.
The table below contains a list of CLIENTDATATYPE values and which classes use them:
CLIENTDATATYPE Values
Value Used for
BINARY %Binary (or any property requiring that there is no Unicode conversion of data)
CURRENCY %Currency
DATE %Date
DOUBLE %Float
INTEGER %Boolean , %Integer
LIST %List
NUMERIC %Numeric
VARCHAR %Name , %String
TIME %Time
TIMESTAMP %TimeStamp
SQL and ODBC Methods
Data type classes include a number of methods and class keywords designed to support interoperability with the Caché SQL relational database, as well as other relational databases.
The OdbcToLogical and LogicalToOdbc methods translate logical data values to and from values used by the Caché SQL ODBC Interface. The ODBC value must match the ODBC type specified by the data type class' ODBCTYPE class keyword.
The ODBCTYPE class keyword specifies the ODBC data type used when a property is projected to ODBC. The definition of the data type class specifies this value. Overriding it prevents a class from working properly with ODBC.
The following ODBCTYPE values are used for the Caché system data types:
ODBCTYPE Values
Value Caché Data Type
BINARY %Binary
CURRENCY %Currency
DATE %Date
DOUBLE %Float
INTEGER %Integer , %Boolean
NUMERIC %Numeric
TIME %Time
TIMESTAMP %TimeStamp
VARCHAR %String , %List , %Name
The SQLCATEGORY Class Keyword
The SQLCATEGORY class keyword specifies the SQL Category that Caché SQL uses to perform operations on the value of data of this data type. Operations controlled by the SQLCATEGORY include comparison operations (such as greater than, less than, or equal to); other operations may also use it. The definition of the data type class specifies this value. Overriding it prevents a class from working properly with SQL.
The following SQLCATEGORY values are used for the Caché system classes:
SQLCATEGORY Values
Value Caché Data Type
CURRENCY %Currency
DATE %Date
DOUBLE %Float
INTEGER %Integer , %Boolean
NAME %Name
NUMERIC %Numeric
STRING %String , %Binary , %List
TIME %Time
TIMESTAMP %TimeStamp
Data Formats and Translation Methods
When handling data, Caché uses a number of different formats, depending on the situation. These have various purposes — such as for displaying data in a human-readable format or for manipulating data programmatically. Caché data types automatically convert data among these formats. If you create your own data type that is a subclass of a Caché data type, any property using your data type automatically includes the methods for converting among the various formats.
You only need to know about these formats and conversions between them if you are either creating a data type not based on a system data type or performing non-standard data manipulation.
The formats are:
If a property uses a system data type (or a data type derived from a system data type), the property automatically includes methods for translation among the various data formats. Though you do not use these methods directly, they serve as the basis for a data type's property-specific methods (called property methods). They include:
Enumerated Properties
Properties can support multiple choice values, also known as enumerated values. To create such a properties, there are two data type class parameters: VALUELIST and DISPLAYLIST.
To specify a list of valid values for a property, use its VALUELIST parameter. The form of VALUELIST is a delimiter-separated list of logical values, where the delimiter is the first character. For instance:
Property Color As %String(VALUELIST = ",red,green,blue");
In this example, VALUELIST specifies that valid possible values are “red”, “green”, and “blue”, with a comma as its delimiter. Similarly,
Property Color As %String(VALUELIST = " red green blue");
specifies the same list, but with a space as its delimiter.
The property is restricted to values in the list, and the data type validation code simply checks to see if the value is in the list. If no list is present, there are no special restrictions on values.
DISPLAYLIST is an additional list that, if present, represents the corresponding display values to be returned by the property's LogicalToDisplay method.
This functionality works by convention: the data type class' LogicalToDisplay and IsValidDT methods must first check for the presence of these class parameters and include code to process these lists if present.