SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Host Variables in COBOL Programs
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
4-16
Date-Time and Interval Data
DATETIME MONTH TO DAY data type, which has no equivalent in SQL/MX. This
example selects the SQL/MP DATETIME value:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
...
01 BILLINGS-REC.
02 HV-CUSTNUM PIC 9(4) COMP.
02 HV-BILLING-DATE PIC X(10).
...
EXEC SQL END DECLARE SECTION END-EXEC.
...
EXEC SQL SELECT custnum, CAST(billing_date AS CHAR(10))
INTO :HV-CUSTNUM, :HV-BILLING-DATE
FROM billings
WHERE custnum = :HV-THIS-CUSTOMER
END-EXEC.
...
Inserting or Updating SQL/MP DATETIME Values Not
Equivalent to DATE, TIME, or TIMESTAMP
To insert or update nonstandard SQL/MP DATETIME values that are not equivalent to
DATE, TIME, or TIMESTAMP, format a COBOL character string in the desired display
format for a date, time, or timestamp. Within an INSERT or UPDATE statement, use
the SQL/MX CAST function to convert the character date-time data to a DATE, TIME,
or TIMESTAMP data type.
If you are using date-time values as input values to the database in statements other
than INSERT or UPDATE (for example, within the WHERE clause of a SELECT
statement), you must also use the CAST function to convert the character string to a
DATE, TIME, or TIMESTAMP data type.
Example
Suppose that an SQL/MP database has a BILLINGS table that consists of the
CUSTNUM and BILLING_DATE columns. The BILLING_DATE column has a
DATETIME MONTH TO DAY data type, which has no equivalent in SQL/MX. This
example inserts a customer number and date-time value into that table:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
...
01 BILLINGS-REC.
02 HV-CUSTNUM PIC 9(4) COMP.
02 HV-BILLING-DATE PIC X(5).
...
EXEC SQL END DECLARE SECTION END-EXEC.
...
EXEC SQL INSERT INTO billings
VALUES (:HV-CUSTNUM,
CAST(:HV-BILLING-DATE AS DATETIME MONTH TO DAY))
END-EXEC.
...
COBOL
COBOL