When does type conversion occur?
In Genero BDL, primitive data type conversion is implicit when possible.
The runtime system performs data conversion implicitly without objection, as long as the data conversion is valid. A date value can be converted to a character string, but a character string can only be converted to a date if the string represents a valid date in the current date format settings (DBDATE).
Implicit data type conversion can for example occur in the following cases:
- In a
LET
assignment, - In an expression, when operands are not of the same data type,
- In
DISPLAY
instructions, orPRINT
instructions in reports, - In dialogs, when values must be converted to strings to be displayed in form fields,
- When passing and returning values to/from a function,
- When serializing numeric values in
UNLOAD
, JSON methods, etc.
In the next code example, implicit data type conversion occurs
- When assigning the result of the
DECIMAL
expression to theVARCHAR
variablev
, - When assigning a
VARCHAR
value to theDECIMAL
variabled
, - When passing the
DECIMAL
valued
to functionfunc()
, expecting aVARCHAR
, - When returning the
VARCHAR
value from thefunc()
function, - When displaying the
DECIMAL
value (formatting rules apply).
MAIN
DEFINE v VARCHAR(50),
d DECIMAL(10,2)
LET v = 1234.50 * 2 -- 1.
LET d = v -- 2.
LET d = func(d) -- 3. and 4.
DISPLAY d -- 5.
END MAIN
FUNCTION func(v)
DEFINE v VARCHAR(50)
DISPLAY v
RETURN v -- 4.
END FUNCTION