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 COBOL523627-004
4-14
Date-Time and Interval Data
format you want and retrieving the value by using the DATEFORMAT function. See the
DATEFORMAT function in the SQL/MX Reference Manual.
For example, if a table in the database has this column definition:
HIRE_DATE DATE
The host variable representation for May 28, 1992, in DEFAULT format is:
A DATE host variable in DEFAULT format is represented as a 10-character string with
hyphens (-) as field separators.
Selecting Standard Date-Time Values
To retrieve standard date-time values (DATE, TIME, or TIMESTAMP, or the SQL/MP
equivalents) from the database, declare a date-time (DATE, TIME, or TIMESTAMP)
host variable. For the required number of digits for DATE, TIME, or TIMESTAMP
values, see Table 4-2 on page 4-7.
Table 4-3 lists the lengths of the target arrays for TIME and TIMESTAMP values, which
depend on the precision (the number of digits in the fractional seconds).
The TIME default precision is 0 (zero), and the TIMESTAMP default precision is 6.
Example
If a database has a BILLINGS table that consists of the CUSTNUM and
BILLING_DATE columns, this example selects the date-time value:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
...
01 BILLINGS-REC.
02 HV-CUSTNUM PIC 9(4) COMP.
02 HV-BILLING-DATE DATE.
Table 4-3. Lengths of Target Arrays for TIME and TIMESTAMP
TIME Precision Length TIMESTAMP Precision Length
TIME 8 TIMESTAMP 26
TIME(0) 8 TIMESTAMP(0) 19
TIME(1) 10 TIMESTAMP(1) 21
TIME(2) 11 TIMESTAMP(2) 22
TIME(3) 12 TIMESTAMP(3) 23
TIME(4) 13 TIMESTAMP(4) 24
TIME(5) 14 TIMESTAMP(5) 25
TIME(6) 15 TIMESTAMP(6) 26
1 9 9 2 0 5 2 8
−−
Year Separator Month Separator Day
COBOL