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
LETassignment, - In an expression, when operands are not of the same data type,
- In
DISPLAYinstructions, orPRINTinstructions 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
DECIMALexpression to theVARCHARvariablev, - When assigning a
VARCHARvalue to theDECIMALvariabled, - When passing the
DECIMALvaluedto functionfunc(), expecting aVARCHAR, - When returning the
VARCHARvalue from thefunc()function, - When displaying the
DECIMALvalue (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