About Character Literals

A character literal is any string of characters enclosed in quotation marks as shown in the following example:

'This is a character string.'
"This is a character string, too."

For convenience, you can enter character literals without the delimiting quotation marks; however, quotation marks are required in some situations. The rules for using quotation marks are described in Quotation Marks.

Valid and Invalid Literals

The following are examples of valid literals:

‘abc’Is a character string.
‘ab”C’Is a character string.
Is a null string.
3.14159Is a number literal.
9Is a number literal.
‘10.99’Is a character string.
‘John’s toy boat’Is a character string.
‘ABCd_EfG’Is a character string.
‘1234A’Is a character string.

The following are examples of invalid literals:

1 23Spaces are not permitted in number literals.
$10.99Periods are not permitted in an unquoted character string, and the dollar sign is not permitted in a number literal.
‘John’s toy boat’‘John’ is a valid character string, but the rest of the line is invalid.

About Conditional Expressions

Conditional expressions use the conditional operators to compare operands (typically, value expressions). When evaluated, conditional expressions yield a logical result (true or false), depending if  the condition is satisfied.

Conditional Operators

Operator

Condition Being Evaluated

expr = expr

The values are equal.

expr <> expr

The values are not equal.

expr < expr

The left-hand value is less than the right-hand value.

expr <= expr

The left-hand value is less than or equal to the right-hand value.

expr > expr

The left-hand value is greater than the right-hand value.

expr >= expr

The left-hand value is greater than or equal to the right-hand value.

expr between expr and expr

The value before BETWEEN is greater than or equal to the value to the right of BETWEEN and less than or equal to the value to the right of AND.

expr not between expr and expr

The value before NOT BETWEEN is less than the value to the right of NOT BETWEEN and greater than the value to the right of AND.

expr in («expr»)

The value before IN is a member of the list of values to the right of IN.

expr not in («expr»)

The value before NOT IN is not a member of the list of values to the right of NOT IN.

expr is [$]null

The value on the left is $Null.

expr is not [$]null

The value on the left is not $Null.

expr like pattern

The value before LIKE matches the pattern specified to the right of LIKE.

expr not like pattern

The value before NOT LIKE matches the pattern specified to the right of NOT LIKE.

Note: The AND and BETWEEN expressions are not the Boolean AND.

Examples of Conditional Expressions

EmpNum > 1254

Logically true when EmpNum is 1254.

DepNum >= EmpNum

Logically true when DepNum is greater than or equal to EmpNum

FirstName = ‘Smith’

Logically true when FirstName is Smith.

DeptDesc <> ‘Sports’

Logically true when DeptDesc is anything but Sports.

EmpNum between 1000 and 2000

Logically true when EmpNum is in the range 1000-2000.

LastName like ‘% ith$’

Logically true when LastName matches the given pattern.

Event.EventName in (‘F1′,’F2′,’Escape’)

Logically true when EventName is in the list.

ProdCode not between 542 and 863

Logically true when ProdCode is outside the range 542-863.

LastName not in (‘Smith’,’Jones’)

Logically true when LastName is not in the list.

FirstName not like ‘ Sm%’

Logically true when Firstname fails to match the pattern.

Simple conditional expression can be combined into more complex Boolean expressions by using Boolean operators. Also, the Boolean NOT can be used to achieve the same result as the NOT version of BETWEEN, LIKE, and IN.

 

See Also

About Boolean Expressions

Pattern Matching

The conditional operators LIKE and = (equals) can be used to construct expressions in which the condition involves matching a value to a pattern rather than to another explicit value.

The patterns are usually quoted character strings constructed using special wildcard characters in addition to literal characters.

LIKE Patterns

Patterns for use with the LIKE operator can use the following wildcard characters:

  • the underscore (_) matches any single character

  • the percent sign (%) matches zero or any number of characters

For example, the pattern

‘_ ob%’

matches any character string whose second and third letters are ob, followed by zero or more characters. Robert, Bob, and Robin (among others) would match this pattern. Therefore, the expression

FirstName like ‘_ ob%’

is logically true if the value of FirstName is Robert, Bob, Robin, or any other string that matches the given pattern.

If you need to use a percent sign or underscore as a literal character in the pattern, you must “escape” the wildcard character by inserting a backslash ( ) preceding the wildcard.  You must also escape the backslash (two backslashes in total) as shown in the following example:

Grad like ‘100\%’

Very complex expressions can be used as patterns in a LIKE comparison. For example, if SuffixVar is a variable whose value is %, then the expression

FirstName like $ concat(‘S_e%p, SuffixVar)

is logically true if FirstName matches the pattern S_E%p%.

= (Equals) Patterns

Patterns for use with the = (equals) operator also support a wildcard character for pattern matching. The question mark (?) matches any number of characters at the end of a string. The following example

DeptNum= ‘D56’?

is logically true if DeptNum begins with the characters D56. Notice that the question mark must appear outside the pattern string.

If you wish to use the question mark as a literal character, it must be included in the pattern string (i.e., within the quotation marks). The following example

RemarkField = ‘Smith?’

is logically true only if the value of RemarkField is exactly Smith?.

The question mark wildcard can be appended to any atomic expression (i.e., literals, object names, and temporary names) provided that the expression has a character data type (i.e., ALPHA, CHAR, VARALPHA, and VARCHAR).

For example, suppose that LastName is a field in the fCustomer form, having the value Sm//. The expression

Surname = fCustomer.LastName?

is logically true if SurName begins with Sm. The trailing blanks in the pattern are ignored when the question mark is applied to a pattern that is not a literal.

If LastName has the value Sm?//, then the expression

Surname = fCustomer.Lastname

is logically true only if Surname is exactly Sm?.

Using the question mark wildcard in an = (equals) expression is equivalent to using a trailing percent sign wildcard in a LIKE expression. For example, the following expressions are equivalent:

FirstName = ‘ Sm’?

FirstName like ‘ Sm%’

 

Evaluation Order of Functional Expressions

Functional expression are evaluated in stages. Evaluation starts with the most nested argument, and works outwards. If the innermost nest consists of several arguments, the arguments are evaluated from left to right. To change the order of evaluation, use parentheses to change the nesting level.

Consider the following example:

$minof($left(TelNo,3),var1+var2)

Because TelNo is the first argument of the innermost nest, the value of TelNo is determined first. If TelNo is a character-type field whose value is ‘416-555-1212’, then the expression is treated as if it reads

$minof($left(‘416-555-1212’,3),var1+var2)

The other arguments of the innermost nest are literals, so $left is now evaluated, returning the result ‘416’, a character string. The expression is now treated as if it reads

$minof(‘416’,var1+var2)

If the value of var1 is 400 and the value of var2 is 1, then the second argument of $minof evaluates to 401:

$minof(‘416’,401)

Because one of the operands of the $minof function is numeric, all the other operands must be converted. The character string ‘416’ is therefore converted to the number 416:

$minof(416,401)

Finally, the $minof function is applied, returning the result 401.

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

pt_BRPortuguese