Problem:
Using DB2 CURRENT DATE/TIME Special Register with OpenESQL
Resolution:
You can use the DB2 CURRENT DATE/TIME special register with OpenESQL, but the only acceptable way to use CURRENT DATE/TIME is embedded in a SELECT, UPDATE or INSERT statement. OpenESQL does not recognize EXEC SQL VALUE (CURRENT DATE) INTO :HOSTVAR END-EXEC
The attached program shows different forms of the CURRENT DATE/TIME.
$set sql(dbman=odbc)
working-storage section.
EXEC SQL INCLUDE SQLCA END-EXEC
01 db-timestamp pic x(26) Value Spaces.
01 db-date pic x(10) Value Spaces.
01 db-date1 pic x(10) Value Spaces.
01 db-time pic x(8) Value Spaces.
01 db-time1 pic x(8) Value Spaces.
Procedure Division.
EXEC SQL
CONNECT TO 'udbsample' USER 'userid.password'
END-EXEC
EXEC SQL
SELECT (current timestamp) INTO :db-timestamp FROM employee where empno='000340'
END-EXEC
EXEC SQL
UPDATE employee
SET HIREDATE = (current date)
WHERE empno='000340'
END-EXEC
EXEC SQL
SELECT (current time) INTO :db-time FROM employee where empno='000340'
END-EXEC
EXEC SQL
SELECT {fn curdate()} INTO :db-date1 FROM employee where empno='000340'
END-EXEC
EXEC SQL
SELECT {fn curtime()} INTO :db-time1 FROM employee where empno='000340'
END-EXEC
EXEC SQL
DISCONNECT CURRENT
END-EXEC
Stop run.