Logical data represents a binary value—YES (TRUE) or NO (FALSE). You use logical values and expressions in many parts of your application. Many functions, methods, and procedures return values that report the success or failure of their execution. In your ABL code, you typically check a return value to determine how to continue execution.

When you define a logical variable, you can initialize it. The possible values are YES, NO, TRUE, or FALSE. YES is the same as TRUE, and NO is the same as FALSE. If you do not initialize the variable when you define it, then the default initial value is NO.

Logical expressions

A logical expression can contain a combination of comparison and logical operators. The comparison operators include <, >, <=, >=, and =. In addition, ABL provides the logical operators AND, OR, and NOT.

Operator Example Explanation
AND CreditLimit = 1000 AND Country = "USA" Checks whether the CreditLimit is 1000 and the Country is USA.
OR Country = "UK" OR Country = "USA" Checks whether the Country is either UK or USA.
NOT (NOT (Balance = 0)) AND Country = "USA" Checks whether the Balance is not zero and the Country is USA.
When using a combination of comparison and logical operators, there are often many ways to filter data using different expressions. The following examples are equivalent:
(NOT (Balance = 0)) AND Country = "USA"
Balance <> 0 and Country = "USA"

Precedence of operators

As with numeric expressions, a logical expression also has a precedence of operators. A best practice is to use parentheses to explicitly control the order of evaluation of a logical expression, just as you do for numeric expressions.

The following example code shows a logical expression that uses parentheses. This expression uses comparison operators and the logical operators AND and NOT.
FOR EACH Customer WHERE (NOT (Customer.CreditLimit)) > dTotal AND 
       (Customer.Balance = 0):
  /* do something with the records that match the where clause */
END.
 . . .

Logical operators containing expressions that evaluate to the Unknown value (?)

The following rules apply when performing logical operations (AND, OR, NOT):
  • For an AND operation, the result is FALSE if either operand evaluates to FALSE (even if one of the operands is the Unknown value (?)).
  • For an OR operation, the result is TRUE if either operand evaluates to TRUE (even if one of the operands is the Unknown value (?)).
  • In all other cases, the result is the Unknown value (?) if an operand evaluates to the Unknown value (?).