Back to Contents
The data types supported by the language.
Data Type |
Description |
String Data Types |
CHAR |
Fixed size character strings. |
VARCHAR |
Variable size character strings. |
STRING |
Dynamic size character strings. |
Date and Datetime Data Types |
DATE |
Simple calendar dates. |
DATETIME |
High precision date and hour data. |
INTERVAL |
High precision time intervals. |
Numeric Data Types |
INTEGER |
4 byte integer. |
SMALLINT |
2 byte integer. |
FLOAT |
8 byte floating point decimal. |
SMALLFLOAT
|
4 byte floating point decimal. |
DECIMAL |
High precision decimals. |
MONEY |
High precision decimals with currency formatting. |
Large Data Types |
BYTE |
Large binary data (images). |
TEXT |
Large text data (documents). |
See also: Data conversions, Variables,
Programs.
Purpose:
The CHAR data type is a fixed length, character string data type.
Syntax:
CH
AR[ACTER] [ (size) ]
Notes:
- When size is not specified, the default length is 1
character.
- There is no maximum size limitation; it depends on available memory.
- Variables are always filled with trailing blanks, but these are not
significant in comparisons.
- Variables are initialized to NULL in functions, modules and globals.
- Sub-strings can be extracted with the substring operator
(v[x,y]).
- You can concatenate strings with the double pipe
operator (||).
Warnings:
- The CHAR type is not limited to 32767 characters.
Example:
01
MAIN
02
DEFINE c CHAR(100)
03
LET c = "abcdef"
04
DISPLAY c
05
END MAIN
Purpose:
The VARCHAR data type is a variable length character string data type, with
a maximum size.
Syntax:
VARC
HAR [ ( maxsize, [
reserve ] ) ]
Notes:
- When maxsize is not specified, the default length is 1 character.
- There is no maximum size limitation, it depends on available memory.
- The reserve is not used, it is supported for compatibility with the
SQL data type.
- Variables have significant trailing blanks: Value "abc
" is different from "abc".
- Variables are initialized to NULL in functions, modules and globals.
- Sub-strings can be extracted with the substring operator
(v[x,y]).
- You can concatenate strings with the double pipe
operator (||).
Warnings:
- The VARCHAR type is not limited to 255 characters.
Example:
01
MAIN
02
DEFINE c VARCHAR(10,5)
03
LET c = "abcdef "
04
DISPLAY c || "."
05
END MAIN
Purpose:
The STRING data type is a variable length, dynamically allocated character string data
type, without limitation.
Syntax:
STRING
Notes:
- The behavior is similar to the VARCHAR data
type.
- There is no size limitation, it depends on available memory.
- Variables have significant trailing blanks: Value "abc
" is different from "abc".
- Variables are initialized to NULL in functions, modules and globals.
- You can concatenate strings with the double pipe
operator (||).
- Variables declared with this type can use built-in class methods such as
getLength() or toUpperCase().
Warnings:
- Because STRING variables have no size, they cannot be
used as SQL parameters.
For example, you cannot use a STRING variable in EXECUTE:
EXECUTE stmt USING string_variable
However, you can use it as argument for the PREPARE
instruction:
PREPARE stmt FROM string_variable
- The STRING data type cannot be used in FORMONLY
field definitions.
- Sub-strings cannot be extracted with the subscript operator v[x,y].
- The getLength() method counts the number of characters, including trailing
blanks.
This is not the same behavior as the
LENGTH()
built-in function, which ignores trailing blanks.
Tips:
- Variables defined as STRING data types are managed by the runtime system efficiently, using many
optimization techniques. Therefore, it is strongly recommended that you use
STRING
instead of CHAR/VARCHAR data types in code requiring fast execution.
Methods:
Object Methods |
Name |
Description |
append( str STRING )
RETURNING STRING |
Returns a new string made by adding str to the end of the current
string. |
equals( src STRING )
RETURNING INTEGER |
Returns TRUE if the
string passed as parameters matches the current string. If one of the
strings is NULL the method
returns FALSE. |
equalsIgnoreCase( src STRING )
RETURNING INTEGER |
Returns TRUE if the
string passed as parameters matches the current string, ignoring
character case. If one of the strings is NULL
the method returns FALSE. |
getCharAt( pos INTEGER )
RETURNING STRING |
Returns the character at the position pos (starts at 1). Returns NULL
if the position does not match a character position in the current string. |
getIndexOf( str STRING, spos INTEGER
)
RETURNING INTEGER |
Returns the position of the sub-string str in the current string,
starting from position spos. Returns zero if the sub-string was not
found. |
getLength( )
RETURNING INTEGER |
Returns the number of characters of the current string, including
trailing spaces. |
subString( spos INTEGER, epos INTEGER )
RETURNING STRING |
Returns the sub-string starting at spos and ending at epos.
Returns NULL if the
positions do not delimit a sub-string in the current string. |
toLowerCase( )
RETURNING STRING |
Converts the current string to lowercase. |
toUpperCase( )
RETURNING STRING |
Converts the current string to uppercase. |
trim( )
RETURNING STRING |
Removes white space characters from the beginning and end of the current
string. |
trimLeft( )
RETURNING STRING |
Removes white space characters from the beginning of the current string. |
trimRight( )
RETURNING STRING |
Removes white space characters from the end of the current string. |
Example:
01
MAIN
02
DEFINE s STRING
03
LET s = "abcdef "
04
DISPLAY s || ". (" || s.getLength() || ")"
05
IF s.trimRight() = "abcdef" THEN
06
DISPLAY s.toUpperCase()
07
END IF
08
END MAIN
Purpose:
The INTEGER data type is used for storing large whole numbers.
Syntax:
INT[EGER]
Notes:
- Storage is based on 4 bytes of signed data ( = 32 bits ).
- INTEGER value range is from -2,147,483,647 to +2,147,483,647.
- Value -2,147,483,648 is reserved for the representation of NULL.
- Variables are initialized to zero in functions, modules and globals.
- INTEGER values can be converted to strings.
Example:
01
MAIN
02
DEFINE i INTEGER
03
LET i = 1234567
04
DISPLAY i
05
END MAIN
Purpose:
The SMALLINT data type is used for storing small whole numbers.
Syntax:
SMALLINT
Notes:
- Storage is based on 2 bytes of signed data ( = 16 bits ).
- SMALLINT value range is from -32,767 to +32,767.
- The value -32,768 is reserved for the representation of NULL.
- Variables are initialized to zero in functions, modules and globals.
- SMALLINT values can be converted to strings.
Example:
01
MAIN
02
DEFINE i SMALLINT
03
LET i = 1234
04
DISPLAY i
05
END MAIN
Purpose:
The FLOAT data type stores values as double-precision floating-point binary
numbers with up to 16 significant digits.
Syntax:
{ FLOAT | DOUBLE PRECISION } [(precision)]
Notes:
- Storage is based on 8 bytes of signed data ( = 64 bits ).
- FLOAT values have the same range as the double data type in C.
- The precision can be specified but it has no effect in programs.
- Variables are initialized to zero in functions, modules and globals.
- FLOAT values can be converted to strings according to the DBMONEY
environment variable (defines the decimal separator).
Tips:
- This data type it is not recommended for exact decimal storage; use the
DECIMAL
data type instead.
Purpose:
The SMALLFLOAT data type stores values as single-precision floating-point
binary numbers with up to 8 significant digits.
Syntax:
{ SMALLFLOAT | REAL }
Notes:
- Storage is based on 4 bytes of signed data ( = 32 bits ).
- SMALLFLOAT values have the same range as the float data type in C.
- Variables are initialized to zero in functions, modules and globals.
- SMALLFLOAT values can be converted to strings according to the
DBMONEY
environment variable (which defines the decimal separator).
Tips:
- The data type it is not recommended for exact decimal storage; use the
DECIMAL
data type instead.
Purpose:
The DECIMAL data type is provided to handle large numeric values with exact
decimal storage.
Syntax:
{ DEC[IMAL] | NUMERIC }
[ ( precision[,scale]
)
]
Notes:
- The number of significant digits is specified by the precision.
- The maximum number of significant digits (precision) is 32.
- The default for the precision is 16.
- The number of decimal digits is specified by the scale.
- When no scale is specified, the Decimal is a floating point
decimal.
- The largest absolute value that a DECIMAL(p,s) can store without errors is
10p-s - 10s.
- Variables are initialized to NULL in functions, modules and globals.
- Decimal values can be converted to strings according to the DBMONEY
environment variable (which defines the decimal separator).
Warnings:
- When you try to assign a value larger than the Decimal definition (for
example, 12345.45 into DECIMAL(4,2) ), no out of range error occurs, and the
variable is assigned with NULL. If WHENEVER ANY ERROR is used, it raises error -1226.
If you do not use
WHENEVER ANY ERROR, the STATUS variable is not
set to -1226..
Example:
01
MAIN
02
DEFINE d1 DECIMAL(10,4)
03
DEFINE d2 DECIMAL(10,3)
04
LET d1 = 1234.4567
05
LET d2 = d1 / 3 -- Rounds decimals to 3 digits
06
DISPLAY d1, d2
07
END MAIN
Purpose:
The MONEY data type is provided to store currency amounts with exact
decimal storage.
Syntax:
MONEY [ (precision[,scale])
]
Notes:
- The behavior is similar to the DECIMAL
data type, with some differences.
- The number of significant digits is specified by the precision.
- The maximum number of significant digits (precision) is 32.
- The default for the precision is 16.
- The number of decimal digits is specified by the scale.
- When no scale is specified, it defaults to 2 or 3 according to
locale settings.
- Variables are initialized to NULL in functions, modules and globals.
- Money values can be converted to strings according to the DBMONEY
environment variable (which defines the currency sign and the decimal separator).
Warnings:
- See the DECIMAL data type.
Purpose:
The DATE data type stores calendar dates with a Year/Month/Day representation.
Syntax:
DATE
Notes:
- Storage is based on a 4 byte integer representing the number of days
since 1899/12/31.
- Date arithmetic is based on a number of days: D1-D2 = NDays; D2+NDays =
D1.
- Date / String conversions depend on the DBDATE
environment variable.
- Several built-in functions and constants are available such as MDY() and
TODAY.
Warnings:
- Variables are initialized to zero (=1899/12/31) in functions, modules and
globals.
Tips:
- Integers can represent dates as a number of
days starting from 1899/12/31 and can be assigned to dates, but it is not recommended
that you directly assign integers to
dates, for source code readability .
- As Date/String conversion is based on an environment setting, it is not
recommended that you hardcode strings representing Dates.
Example:
01
MAIN
02
DEFINE d DATE
03
LET d = TODAY
04
DISPLAY d, " ", d+100
05
END MAIN
Purpose:
The DATETIME data type stores date and time data with time units from the year to fractions of a second.
Syntax:
DATETIME qual1 TO qual2[(scale)]
Notes:
- The qualifiers qual1 and qual2 define the size of the
Datetime.
- The qualifiers can be: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, FRACTION[(scale)].
- The scale defines the number of significant digits of the fractions of
a second.
- The built-in CURRENT constant provides current system date/time.
- Datetime arithmetic is based on the INTERVAL
data type: ( Datetime1 - Datetime2 = Interval; Datetime2 + Interval =
Datetime1 ).
- DATE data can be used in Datetime arithmetic (
Datetime1 - Date1 = Interval )
- Variables are initialized to NULL in functions, modules and globals.
- The language supports Datetime
Literals with a specific notation.
- Datetime values can be converted to Strings by following the standard
format of Datetimes (YYYY-MM-DD hh:mm:ss.fffff).
Example:
01
MAIN
02
DEFINE d1, d2 DATETIME YEAR TO MINUTE
03
LET d1 = CURRENT YEAR TO MINUTE
04
LET d1 = "1998-01-23 12:34"
05
DISPLAY d1, d2
06
END MAIN
Purpose:
The INTERVAL data type stores spans of time as Year/Month or
Day/Hour/Minute/Second/Fraction units.
Syntax:
INTERVAL qual1[(precision)] TO qual2[(scale)]
Notes:
- The qualifiers qual1 and qual2 define the size of the
Interval.
- The qualifiers can be: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, FRACTION[(scale)].
- The precision defines the number of significant digits of the first
qualifier.
- The scale defines the number of significant digits of the fractions of
a second.
- Variables are initialized to NULL in functions, modules and globals.
- The language supports Interval
Literals with a specific notation.
- Interval values can be converted to Strings by following the standard
format of Datetimes (YYYY-MM-DD hh:mm:ss.fffff).
Warnings:
- There are two kind of Interval data types: Year/Month and
Day/Hour/Minute/Second/Fraction intervals.
Example:
01
MAIN
02
DEFINE i1 INTERVAL YEAR TO MONTH
03
DEFINE i2 INTERVAL DAY(5) TO MINUTE
04
LET i1 = "2342 4"
05
LET i2 = "23423 12:34"
06
DISPLAY i1, i2
07
END MAIN
Purpose:
The BYTE data type stores any kind of binary data such as images or
sounds.
Syntax:
BYTE
Notes:
- The Byte data type is a complex type that cannot be used like simple types
such as Integers or Chars.
- Byte variables are actually 'locators' for a large object stored in a file
or in memory.
Warnings:
- A Byte variable must be initialized with the LOCATE
instruction before usage.
Example:
01
MAIN
02
DEFINE b BYTE
03
DATABASE stock
04
LOCATE b IN MEMORY
05
SELECT bytecol INTO b FROM mytable
06
END MAIN
Purpose:
The TEXT data type stores large ASCII text data.
Syntax:
TEXT
Notes:
- The Text data type is a complex type, unlike simple types such
as Integers or Chars.
- Text variables are actually 'locators' for a large object stored in a file
or in memory.
Warnings:
- A Text variable must be initialized with the LOCATE instruction before
usage.
Example:
01
MAIN
02
DEFINE t TEXT
03
DATABASE stock
04
LOCATE t IN FILE "/tmp/mytext.txt"
05
SELECT textcol INTO t FROM mytable
06
END MAIN