About Functional Expressions

The software provides a host of built-in functions that process given arguments in a variety of ways. An expression consisting of a function and its arguments (typically, value expressions) is called a functional expression.

Examples of functional expressions are

$length(‘Smith’)

Evaluates to 5

$cos(0)

Evaluates to 1

$log10(2*50)

Evaluates to 2

$year(19990923)

Evaluates to 1999

$maxof($absolute(-10),4+5)

Evaluates to 10

General Performance

Functions are a special class of operator, but they perform much like arithmetic operators; they take one or more given values, perform an operation using those values, and return a result. The value of the result depends on the function.

The function’s arguments are similar to the arithmetic operands. Like arithmetic operands, the arguments can consist of literals or value expressions, including other functional and arithmetic expressions as shown in the following example:

$absolute(-7)

The functional expression shown above consists of the argument -7 and the function keyword $absolute. The function $absolute returns the absolute (i.e., unsigned) value of its argument (in this case, 7).

Complex Arguments

If the argument is a complex expression, the argument is evaluated before the function is applied. For example, in the expression

$absolute(6-11)

the arithmetic expression 6-11 is evaluated first, yielding $absolute(-5). Then the final result (5) is determined.

Functional expressions can act as arguments to other functions. For example, the expression

$toupper($substring(‘abcdef’,2,3))

evaluates to

$toupper(‘bcd’)

which in turn evaluates to

‘BCD’

Data Type of Arguments and Results

Each function expects arguments of a certain data type; however, the function accepts arguments of any data type and appropriately converts any argument that does not conform to the expected type.

Related Information

About Data Types

About Data Types

Any value expression used in an application – including the names of objects that represent values – must conform to one of the available data types.

Data Types and Objects

Objects that represent values (constants, variables, fields and form fields) have an explicit data type attribute defined in the Object Dictionary. Value expressions that are not defined objects take implicit data types. The data type of an object or expression determines the values that an object or expression can represent and how the software handles the value.

The software recognizes nine different data types:

  • ALPHA, VARALPHA, CHAR and VARCHAR are character (string) data types.
  • INT, LONGINT, VASTINT, and NUMERIC are number data types.
  • DATE is a date data type.

See Also

Character Data Types

Conversion Between Data Types

Data Types and Storage of Values

Data Types and the Use of Database Indexes

How To Use Data Types

Implicit Data Types of Literals

Number Data Types

The Date Data Type

Character Data Types

Each character data type represents a particular combination of storage space usage and letter case treatment. ALPHA, VARALPHA, CHAR, and VARCHAR values can contain letters, digits, spaces, symbols, and hexadecimal codes.

Character Data Type Characteristics

Data TypeData LengthTreatment of Letter Case
ALPHAFixed (padded with trailing blanks if necessary)Case insensitive (but, case is stored and visible on display)
VARALPHAVariableCase insensitive (but, case is stored and visible on display)
CHARFixed (padded with trailing blanks if necessary)Case insensitive
VARCHARVariableCase insensitive

See Also

About Conditional Expressions

Conversion Between Data Types

Data Types and Storage of Values

Data Types and the Use of Database Indexes

How To Use Data Types

Number Data Types

INT, LONGINT, and VASTINT represent varying sizes of numbers and varying storage space usage, but otherwise receive identical treatment by the software. INT, LONGINT, and VASTINT values can contain only digits.

The NUMERIC data type represents numbers stored in character form and may therefore contain a leading sign (+, -) or an embedded decimal point, or both. Spaces are permitted before and after the leading sign, but not between digits.

Number Data Type Characteristics

Data TypeDecimalsValid Range
(Significant Digits)
Storage Occupied
INTAny number-32768 to 32767Two bytes
LONGINTAny number-2147483647 to 2147483647Four bytes
VASTINTAny number15 significant digitsEight bytes
NUMERICAny number15 digitsOne byte per character

See Also

About Conditional Expressions

Conversion Between Data Types

Data Types and Storage of Values

Data Types and the Use of Database Indexes

How To Use Data Types

The Date Data Type

DATE indicates that a value consists of eight digits representing a date in the form YYYYMMDD. For example, 19990821 is August 21, 1999.

Note: If you are using Zim in conjunction with a third-party SQL database engine, the format of dates can differ from that described here. In such cases, your code must avoid making any assumptions about the format of date fields.

Dates and numbers can be freely interchanged. When a number is converted to a date, the number is assumed to adhere to the YYYYMMDD format, so that dividing the number by 10,000 (for example) yields the year. You can subtract one date from another to find the number of days between them, or you can add or subtract a number of days to or from a date to generate another date (i.e., date arithmetic).

The software provides a number of functions to manipulate DATE values. These functions ($year, $ monthname, $ addmonths, $weekday, etc) are described in the Language Reference book of this online help.

Date Data Type Characteristics

Data TypeDecimalsValid RangeStorage Occupied
DATENoneJanuary 1, 0001 to December 31, 9999Eight bytes

See Also

About Conditional Expressions

Conversion Between Data Types

Data Types and Storage of Values

Data Types and the Use of Database Indexes

How To Use Data Types

How To Use Data Types

The following are the character data types:

  • alpha

  • varalpha

  • char

  • varchar

The following are the numeric data types:

  • int

  • longint

  • vastint

  • numeric

The following is the other data type:

  • date

Alpha Data Type

A character string of fixed length (uses a pre-defined amount of storage space). Pads with trailing blanks if necessary. Case insensitive in sorts, compares, and so on, but case is stored and is apparent on display.

Varalpha Data Type

A character string of variable length (uses only as much storage space as data requires). Ignores trailing blanks if entered. Case insensitive in sorts, compares, and so on, but case is stored and is apparent on display.

Char Data Type

A character string of fixed length (uses a pre-defined amount of storage space). Pads with trailing blanks if necessary. Case sensitive in sorts, compares, and so on.

Varchar Data Type

A character string of variable length (uses only as much storage space as data requires). Ignores trailing blanks if entered. Case sensitive in sorts, compares, and so on.

Int Data Type

A numeric value occupying two bytes of storage space. Can contain any number of decimal places, but digit value (ignoring decimal places) must fall between -32768 and 32767.

Longint Data Type

A numeric value occupying four bytes of storage space. Can contain any number of decimal places, but digit value (ignoring decimal places) must fall between -2147483648 and 2147483647.

Vastint Data Type

A numeric value occupying eight bytes of storage space. Can contain any number of decimal places and up to fifteen significant digits (ignoring decimal places).

Numeric Data Type

A number stored in character form. Can include a leading sign (+, -), or an embedded decimal point, or both. Can include spaces between the sign and the first digit, but not between digits.

Date Data Type

A date value occupying eight bytes of storage space. On display, contains eight digits in the form YYYYMMDD. Dates and numbers are freely interchangeable, and date arithmetic is available.

Implicit Data Types of Literals

Literals express values outside of pre-defined application objects. Because literals have no definition in the Object Dictionary, the software assumes a data type for each literal. This implicit data type is determined based on the characters contained in the value, and on whether or not the value is enclosed in quotation marks.

Literals that are enclosed in quotation marks, or that are unquoted but contain letters, are assumed to be character strings. Character strings are always implicitly CHAR.

Unquoted literal values that contain only digits, or digits and a decimal point are assumed to be numbers. Number literals are always implicitly VASTINT.

Constants (literals defined as objects, with names, in the Object Dictionary) can be assigned either the CHAR or VASTINT data type. No other type is permitted. The assigned data type overrides the data type implicit in the value of the constant.

Examples of Implicit Data Types

1234Is implicitly VASTINT.
abcdIs implicitly CHAR.
2.6Is implicitly VASTINT.
a1b2Is implicitly CHAR.
‘1234’Is implicitly CHAR.
‘ abcd’Is implicitly CHAR.
‘-2.6’Is implicitly CHAR.
‘a1b1’Is implicitly CHAR.

See Also

About Conditional Expressions

Conversion Between Data Types

Data Types and Storage of Values

Data Types and the Use of Database Indexes

How To Use Data Types

Data Types and the Use of Database Indexes

The software automatically determines if it can use indexes when it looks for records in the database. If the software cannot use an available index, each record in the record-containing objects must be scanned (a potentially slower process).

In some cases, the software cannot use an available index if the data type of the indexed field and the data type of the comparison value are incompatible.

Data Type Compatibility in Indexed Database Searches

Data Type of Indexed Field

Required Data Type of Comparison Value (for index to be used)

CHAR, VARCHAR

CHAR, VARCHAR

ALPHA, VARALPHA

CHAR, VARCHAR, ALPHA, VARALPHA

Any number data type, DATE

Any data type

Example

If you enter the command

find Employees where EmpNum = 156

and EmpNum is an Indexed field of a character type, you are asking to compare the number 156 to a character field.

In this case, the software does not use the available index, because to do so would produce an incorrect result. The index is sorted internally, based on character comparisons. The literal 156 is implicitly a VASTINT number and cannot be effectively compared to character values.

Instead, the software performs the FIND by checking the 156 against the individual values of EmpNum. Speed of execution is slower than if the index could be used.

To ensure that the index is used, modify the command to read

find Employees where EmpNum = ‘156’

In this case, the literal, because it is enclosed in quotation marks, is implicitly a character data type (CHAR), and can be compared to the indexed EmpNum values, which are explicitly character type.

Data Types and Storage of Values

ALPHA/CHAR and VARALPHA/ VARCHAR Values

If an ALPHA or CHAR object is assigned the value abc///// (with five trailing blanks), it is stored as abc///// (fixed length value).

If a VARALPHA or VARCHAR object is assigned the value abc/////, it is stored as abc without any trailing blanks, but with an indicator that gives the length of the value (variable length value).

Maximum Lenth for ALPHA/CHAR and VARALPHA/VARCHAR

 

ALPHACHARVARAPLHAVARCHAR
32767 bytes32767 bytes32767 bytes32767 bytes

INT and LONGINT Values

INT, LONGINT and VASTINT values are stored “without decimals”. Actually, the decimal information is stored separately.

The “non-decimal” value (value of the significant digits) must fall within the range of the applicable data type.

Examples – INT Values

ValueSignificant DigitsNumber of DecimalsValid Maximum/Minimum Values
123.4123413276.7 / -3276.8
12.3412342327.67 / -327.68
12.341234332.767 / -32.768
0.01234123450.32767 / -0.32768

Examples – LONGINT Values

ValueSignificant DigitsNumber of DecimalsValid Maximum/Minimum Values
1.23456123456521474.83647 / -21474.83647
1234.56123456221474836.47 / -21474836.47

See Also

About Conditional Expressions

Conversion Between Data Types

Data Types and the Use of Database Indexes

How To Use Data Types

Conversion Between Data Types

Zim performs conversions and operations between data types in a different manner than other application development languages. The rules for conversions are embedded in Zim itself, and when performing conversions or comparisons, these rules govern how the different data types are handled.

Implicit Conversions

In general, when you write an expression, you can use objects or literals of any data type, in any combination. However, when the software encounters an expression containing values with mixed data types or a data type incompatible with the requirements of the expression, it applies a number of rules for converting the data types should conversion be necessary.

Character-to-character Comparisons

  1. When values are being compared, VARALPHA and VARCHAR values are treated as if they were ALPHA and CHAR values, respectively.
  2. When two values of type ALPHA are being compared, an ALPHA-type (case insensitive) comparison is performed.
  3. When two values of type CHAR are being compared, a CHAR-type (case sensitive) comparison is performed.
  4. When two values are being compared, one of type CHAR and one of type ALPHA, an ALPHA-type (case insensitive) comparison is performed.

Character-to-number Conversions

  1. When two values – only one of which is a number type – are compared or are processed in an arithmetic operation, the value that is not a number type is converted to a number and a numeric comparison or operation is performed.

Number-to-character Conversions

  1. If a number (type INT, LONGINT, VASTINT) must be converted to a character string for use by a command or function (e.g., to be output by the LIST command or processed by $ substring), the number is converted and right-justified, always producing a result string long enough to hold the largest possible value for that data type (8 characters for INT; 12 characters for LONGINT; 17 characters for VASTINT).
  2. Number literals implicitly take the data type VASTINT and assume a number of decimal places equal to the number that actually appear in the literal. If the software has to convert a number literal to a character string for use by a command or function, it becomes a character string 17 characters long, as indicated in Rule 6.

Date Comparisons

  1. When two values are being compared, only one of which is type DATE, the other value is converted to DATE (if possible) and a DATE comparison is performed.
  2. If a number is converted to a date, it is assumed to be in a YYYYMMDD form (e.g., 19991122 is November 22, 1999).

Arithmetic Operations Involving Dates

  1. When an arithmetic operation is being performed on two values, at least one of which is type DATE, the operation is carried out as summarized below:
val1 + val2

If only one value is type DATE, the other is converted to a number and added (as a number of days) to the date.
If both values are type DATE, a normal arithmetic operation is performed and the result is treated as a number.

val1 – val2

If both values are type DATE, the dates are subtracted to yield the number of days between the two dates.
If val1 is type DATE and val2 is not, val2 is converted to a number (if necessary) and is subtracted (as a number of days) from the date.
If val2 is of type DATE and val1 is not, both values are converted to numbers (if necessary) and a normal arithmetic operation is performed.

val1*val2
val1/val2
val1^val2

Both values are converted to numbers (if necessary) and a normal arithmetic operation is performed.

Date-to-character Conversions

  1. If a DATE value must be converted to a character string, it becomes a string eight characters in length.

Explicit conversion Using Software Functions

Although values are implicitly converted from one data type to another as required, the software provides a number of functions that forcibly convert values from one data type to another.

The conversion functions are $ toalpha, $ tocharacter, $ todate and $ tonumber.

 

See Also

=, , >, >= (Condition)

About Conditional Expressions

Data Types and Storage of Values

Data Types and the Use of Database Indexes

How To Use Data Types

en_CAEnglish