ARG_VAL() returns NULL if no argument
With IBM® Informix® 4GL (I4GL), the
ARG_VAL()
function returns a blank character, if the
index passed to the function references an argument that does not exist. In such case, with Genero,
the ARG_VAL()
function returns
NULL
:$ cat arg_val.4gl
MAIN
DEFINE v VARCHAR(10)
LET v = ARG_VAL(1)
IF v IS NULL THEN
DISPLAY "IS NULL"
ELSE
DISPLAY "IS NOT NULL: [", v, "]"
END IF
END MAIN
$ fglcomp arg_val.4gl && fglrun arg_val.42m
IS NULL
$ c4gl -o arg_val.bin arg_val.4gl && ./arg_val.bin
IS NOT NULL: [ ]
You must review
ARG_VAL()
conditions using the !=
operator, and
add NVL()
to handle NULL
arguments:-- Default is "USER" mode when no argument is passed or when argument
-- is different from "ADMIN"
MAIN
--IF ARG_VAL(1)!="ADMIN" THEN
IF NVL(ARG_VAL(1),"?")!="ADMIN" THEN
DISPLAY "User mode..."
ELSE
DISPLAY "Admin mode..."
END IF
END MAIN
Normally the code should use the NUM_ARGS()
, to check the number of parameters
passed to the program.