The Null String

A null string is a character string of zero length. Unlike the $Null property that indicates that the value is unknown or unassigned, the null string is a known value.

For example, if you have two variables, x and y, both of which are null strings, then the expression

x = ” and y <> ‘abc’

is logically true.

Metacharacters in Character Literals

Certain characters, such as quotation marks and the backslash, have special functions in the software. If you need to use one of these metacharacters as a literal character in a string, you must “escape” the special function by inserting a backslash ( – Escape) preceding the metacharacter as shown in the following example:

‘This is a quotation mark (‘).’
‘This is a backslash (\).’

Any character string containing a metacharacter used as a literal must be enclosed in quotation marks.

Hex Codes in Character Literals

If you need a place a character not normally available from the keyboard into a character literal, use the backslash to create the hex code for that character as shown in the following example:

‘This string has an ASCII escape generated by hex 1B (1B)’

The two characters immediately following a quoted backslash are treated as hex code provided they are either digits from 0 to 9 or letters from A (a) to F (f).

Any character string containing a hex code must be enclosed in quotation marks.

Note: The escape function of the backslash inside quoted character strings can be switched off with a SET ESCAPECHAR command.

Example

Character literals that include hex codes can be useful for sending control codes to printers and terminals. For example, if the ASCII codes SI (hex 0F) and DC2 (hex 12) are used, respectively, to select and cancel condensed printing on your particular printer, use the following sequence of statements to print a report in the condensed mode:

set output printer   % switch serial output to printer
output ‘F’;        % switch condensed print on
…. commands to generate report ….
output ’12’         % switch condensed print off
set output terminal  % switch output back to terminal

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%’

 

Decimals and Rounding

The result of an arithmetic expression contains as many decimal places as are found in the operands of the expression.

If the expression contains several operands with varying numbers of decimal places, the result takes on the number of decimal places found in the operand with the most decimal places.

If the result of the expression is assigned to an object with a numeric data type, the value takes on the number of decimal places defined for that object. If the object has fewer rounded decimal places than the expression’s result, the final value is rounded as shown in the following example:

5/2

Evaluates to 3

5/2.0

Evaluates to 2.5

1+1.01

Evaluates to 2.01

1.01+(5/2)

Evaluates to 3.51

Rounding occurs only after the entire expression has been evaluated. Therefore, in 1.01+(5/2), the fractional part of 5/2 is kept during the addition of 1.01. Because 1.01 has two decimal places, the result also has two decimal places.

pt_BRPortuguese