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, or PRINT 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
  1. When assigning the result of the DECIMAL expression to the VARCHAR variable v,
  2. When assigning a VARCHAR value to the DECIMAL variable d,
  3. When passing the DECIMAL value d to function func(), expecting a VARCHAR,
  4. When returning the VARCHAR value from the func() function,
  5. 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