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-17
Date-Time and Interval Data
INTERVAL Representation
Interval values are represented as character strings, with a separator between the
values of the fields (year-month or day-time). An extra character is generated at the
beginning of the interval string for a sign.
For example, a table in the database has this column definition:
AGE INTERVAL YEAR(2) TO MONTH
The host variable representation for 37 years, 11 months, is:
An INTERVAL host variable is represented as a six-character string, including five
characters—with a hyphen (-) as the field separator—plus a character for the sign.
Selecting Interval Values
To retrieve interval values from the database, declare an INTERVAL host variable the
same length as the number of bytes you expect to store in the array. The SQL/MX
preprocessor adds an extra character for the sign.
Example
A database contains a BILLINGS table consisting of the CUSTNUM, START_DATE,
BILLING_DATE, and TIME_BEFORE_PMT columns. This example selects a customer
number and interval value:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
...
01 BILLINGS-REC.
02 HV-CUSTNUM PIC 9(4) COMP.
02 HV-START-DATE DATE.
02 HV-BILLING-DATE DATE.
02 HV-TIME-BEFORE-PMT INTERVAL DAY(3).
EXEC SQL END DECLARE SECTION END-EXEC.
...
EXEC SQL SELECT custnum, time_before_pmt
INTO :HV-CUSTNUM, :HV-TIME-BEFORE-PMT
FROM billings
WHERE custnum = :HV-THIS-CUSTOMER
END-EXEC.
...
Inserting or Updating Interval Values
To insert or update interval values, format a COBOL interval string in the desired
display format for an interval. The first character is reserved for the sign of the interval.
+ 3 7 1 1
Sign Year Separator Month
COBOL