Boolean operators

Operators AND, OR, and NOT combine Boolean values into a single Boolean expression:

In 4gl, Boolean operators resemble SQL Boolean operators but are not identical to them.

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.

In the tables above, any non-zero operand that is not null is assumed to be TRUE.

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.

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.