Huy,
You aren't the first, and won't be the last. I did a search and found this old Informix-4gl forum post form from 2005 that diverges into discussing this topic
https://comp.databases.informix.narkive.com/VEQoSucd/4gl-compares-null-differently.
The 4gl behaviour is consistent with database logic. Note the output from this little test
CREATE TABLE foo(key INTEGER, data CHAR(10))
INSERT INTO foo VALUES(1,"Y")
INSERT INTO foo VALUES(2,"N")
INSERT INTO foo VALUES(3,NULL)
DISPLAY "Not Equal Y"
DECLARE neqy CURSOR FROM "SELECT key FROM foo WHERE data != 'Y'"
FOREACH neqy INTO key
DISPLAY key
END FOREACH
DISPLAY "Equal Y"
DECLARE eqy CURSOR FROM "SELECT key FROM foo WHERE data = 'Y'"
FOREACH eqy INTO key
DISPLAY key
END FOREACH
DISPLAY "is null"
DECLARE in CURSOR FROM "SELECT key FROM foo WHERE data IS NULL"
FOREACH in INTO key
DISPLAY key
END FOREACH
DISPLAY "is not null"
DECLARE inn CURSOR FROM "SELECT key FROM foo WHERE data IS NOT NULL"
FOREACH inn INTO key
DISPLAY key
END FOREACH
Not Equal Y
2
Equal Y
1
is null
3
is not null
1
How does the database solve this? You define the column as NOT NULL and then you never have to worry about the fact that !="Y" won't include NULL values.
Seb's solution of ensuring that your function get_cfg_val() never returns NULL you could say is the equivalent.
Could we ever do something on the 4gl as an equivalent e.g.
FUNCTION get_cfg_val() RETURNS CHAR(1) NOT NULL
... I don't know. For now you can code at the end of the function ...
RETURN nvl(cfg_val, "N")
... and ensure that NULL is never returned.
OR now that we have initialisers could we then code
DEFINE cfg_val CHAR(1) NOT NULL = "Y"
and have a runtime error if the variable value is ever NULL just like a database. I don't think this would be practical as initialisers aren't aways simple values.
I am a pessimist in this area and think that try as you might, a NULL might sneak in somewhere, and so I prefer a technique that was in that old Informix-4gl link. We called it "test for success" so rather than coding
IF get_cfg_val() != "Y" THEN
ERROR "CFG must be Y"
...
END IF
you code
IF get_cfgl_val() = "Y" THEN
# Value OK
ELSE
ERROR "CFG must be Y"
...
END IF
that way if get_cfg_val() does return NULL, it will be caught as you intend
Reuben