Operators AND, OR, and NOT combine Boolean values into a single Boolean expression:
Operators with AND, OR, and NOT return these results:
|
left operand |
right operand |
result |
AND
|
TRUE |
FALSE |
NULL |
TRUE |
TRUE |
FALSE |
NULL |
FALSE |
FALSE |
FALSE |
FALSE |
NULL |
NULL |
FALSE |
NULL |
For example, true AND false returns false.
OR
|
TRUE |
FALSE |
NULL |
TRUE |
TRUE |
TRUE |
TRUE |
FALSE |
TRUE |
FALSE |
NULL |
NULL |
TRUE |
NULL |
NULL |
For example, true OR false returns true.
NOT
TRUE |
FALSE |
FALSE |
TRUE |
NULL |
NULL |
For example, NOT false is true, and NOT null is null.
When one or both arguments are null, the result can also be null.
For example, if bool1 = TRUE and bool2 = NULL, bool1 AND bool2 returns NULL:
MAIN
DEFINE bool1, bool2 smallint
LET bool1 = TRUE
LET bool2 = NULL
DISPLAY "bool1 = ", bool1
DISPLAY "bool2 = ", nvl(bool2, "NULL")
DISPLAY "bool1 AND bool2 = ", nvl((bool1 AND bool2),"NULL")
LET bool1 = FALSE
LET bool2 = NULL
DISPLAY "bool1 OR bool2 = ", nvl((bool1 OR bool2),"NULL")
LET bool1 = TRUE
LET bool2 = FALSE
DISPLAY "bool1 AND bool2 = ", nvl((bool1 AND bool2),"NULL")
DISPLAY "bool1 OR bool2 = ", nvl((bool1 OR bool2),"NULL")
CALL fgl_getkey()
END MAIN
Obtained results:
bool1 = 1
bool2 = NULL
bool1 AND bool2 = NULL
bool1 OR bool2 = NULL
bool1 AND bool2 = 0
bool1 OR bool2 = 1
4gl tries to evaluate both operands of AND and OR logical operators, even if the value of the first operand has already determined the returned value. The NOT operator is recursive.