NULL test

In 4gl, if any operand of a Boolean comparison is NULL, the value of the comparison is FALSE (rather than NULL), unless the IS NULL keywords are also included in the expression.

Applying the NOT operator to a null value does not change it from FALSE to TRUE.

 

To process expressions with null values in a different way as compared to other values, you can use the IS NULL keywords to test for a null value.

Description: Boolean%20NULL%20Test

In a null test, a 4GL expression can have a large element which is a BYTE or TEXT data type declaring the name of a program variable.

The NULL test is one of the exceptions to the rule that BYTE or TEXT data type variables cannot be used in 4GL expressions.

 

Without the NOT keyword, the comparison returns TRUE if the operand has NULL. Otherwise, it returns FALSE.

If you include the NOT keyword, the comparison returns TRUE if the value of the operand is not null.

 

Here is an example of a NULL test:

MAIN

DEFINE x CHAR(5)

 

IF (100=TRUE)

THEN

  DISPLAY "IF (100=TRUE) returns TRUE"

ELSE

  DISPLAY "IF (100=TRUE) returns FALSE"

END IF

 

IF (100)

THEN

  DISPLAY "IF (100) returns TRUE"

ELSE

  DISPLAY "IF (100) returns FALSE"

END IF

 

INITIALIZE x TO NULL

DISPLAY "INITIALIZE x TO NULL"

 

IF (x IS NULL)

THEN

  DISPLAY "IF (x IS NULL) returns TRUE"

ELSE

  DISPLAY "IF (x IS NULL) returns FALSE"

END IF

 

IF (x IS NOT NULL)

THEN

  DISPLAY "IF (x IS NOT NULL) returns TRUE"

ELSE

  DISPLAY "IF (x IS NOT NULL) returns FALSE"

END IF

 

LET x = "abcd"

DISPLAY "LET x = abcd"

 

IF (x IS NULL)

THEN

  DISPLAY "IF (x IS NULL) returns TRUE"

ELSE

  DISPLAY "IF (x IS NULL) returns FALSE"

END IF

 

IF (x IS NOT NULL)

THEN

  DISPLAY "IF (x IS NOT NULL) returns TRUE"

ELSE

  DISPLAY "IF (x IS NOT NULL) returns FALSE"

END IF

 

END MAIN

This example will return these results:

IF (100=TRUE) returns FALSE

IF (100) returns TRUE

INITIALIZE x TO NULL

IF (x IS NULL) returns TRUE

IF (x IS NOT NULL) returns FALSE

LET x = abcd

IF (x IS NULL) returns FALSE

IF (x IS NOT NULL) returns TRUE

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.