Handling type conversion errors

By default, in case of conversion error, the program flow continues, the target variable is set to NULL and the global STATUS variable is not set.

In order to detect data conversion errors, use the WHENEVER ANY ERROR statement:

MAIN  -- DBDATE set to Y4MD-
  DEFINE v VARCHAR(50), d DATE
  LET v = "2012-99-99"      -- invalid date string
  LET d = v
  DISPLAY status, "/", NVL(d,"NULL")  -- displays 0/NULL
  WHENEVER ANY ERROR CONTINUE
  LET d = v
  DISPLAY status, "/", NVL(d,"NULL")  -- displays -1205/NULL
  WHENEVER ANY ERROR STOP
  LET d = "2012-11-23"  -- valid date, ok
  DISPLAY status, "/", NVL(d,"NULL")  -- displays 0/2012-11-23
  LET d = v   -- program execution stopped with error -1205
END MAIN