Quote from: Sebastien FLAESCH on October 02, 2009, 11:13:21 AM
The nice thing with the comma concat operator is that elements are formatted, compared to ||.
We have in mind to do something like CONCAT(a,b,c).
I will add a request for NVL(expr,default) and IF(expr,trueval,falseval).
Seb
I used to have a nvl() and if() in our libraries in my previous job.
The 1996 version of our nvl is available in the IIUG software repository
FUNCTION nvl(l_original, l_if_null)
DEFINE l_original CHAR(80),
l_if_null CHAR(80)
IF LENGTH(l_original) = 0 THEN
RETURN l_if_null
ELSE
IF l_original[1]="$" THEN # Cope with money fields
LET l_original[1]=" "
END IF
RETURN l_original
END IF
END FUNCTION
... I am sure when we generoised we would've switched to STRINGs (ScottN can share the 2009 version if he wishes).
The if would've been something like
FUNCTION if(a,b,c)
DEFINE a SMALLINT -- colud use BOOLEAN Genero 2.2 on
DEFINE b,c STRING
IF a THEN
RETURN b
ELSE
RETURN c
END IF
END FUNCTION
and used in things like
LET increment = if(x.sort_order = "Asc",1, -1).
The downside is that both sides of the expression are evaluated. So it is suitable for the above example where b,c are constants but not so suitable for
CALL if(x.mode = "insert", insert_record(), update_record())
The thing with these simple library functions like this is if that a number of existing customers have them then there is an argument then we should include them in the language so that any new developers do not need to recreate them from scratch and have that functionality from day one, the negative is that existing customers may already have those functions as different names, or similar functions with the same name.