View previous topic :: View next topic
|
Author |
Message |
passion_sujesh
New User
Joined: 14 Mar 2008 Posts: 74 Location: India,Chennai
|
|
|
|
Hi,
I am using 'ADD_MONTHS' table to calculate date in a cobol program.
EXEC SQL
SELECT ADD_MONTHS(:WS-date1,:WS-year)
INTO :WS-date2
FROM SYSIBM.SYSDUMMY1
END-EXEC
I am getting a compilation error 'UNDEFINED OR UNUSABLE HOST VARIABLE "WS-YEAR" .
Can any one let me know if the year part must be a numeric expression only. Something like:
EXEC SQL
SELECT ADD_MONTHS(:WS-date1,+4) INTO :WS-date2
FROM SYSIBM.SYSDUMMY1
END-EXEC
Thanks in advance,
Sujesh. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
How are the columns in the table and the host variables defined? |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
I am not sure what ADD_MONTHS table is but DB2 is very good at date arithmetic.
Code: |
EXEC SQL
SET :WS-DATE2 = DATE(:WS-DATE1) + :WS-NUM-MONTHS MONTHS
END-EXEC.
|
|
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
if you want to use a host-variable as a date,it is always smart to use date(:hv) |
|
Back to top |
|
|
Prakash J
New User
Joined: 23 May 2012 Posts: 14 Location: India
|
|
|
|
Hello,
You can use.
The host variable you are using to add no. of months (in your code, :WS-year) should be defined S9(2) COMP OR S9(2) COMP-3. May be, you defined it as 9(2).
- Prakash |
|
Back to top |
|
|
|