IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

is '0001-01-01' a valid date in DB2


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Sikkandhar

New User


Joined: 03 Dec 2007
Posts: 61
Location: Bangalore

PostPosted: Thu Nov 29, 2012 12:27 pm
Reply with quote

Hi,

I have the sql in Cobol DB2 program which gives -304 as SQLCODE

Code:
EXEC SQL                                               
     SET :VAR1   =                           
         DATE (CURRENT DATE) - DATE (:VAR2) 
END-EXEC         


Where VAR2 has a value '0001-01-01'. The above query errors out with Sqlcode -304.

If i execute the same query in SPUFI, am getting the result. It is not erroring out.

Code:
SELECT                                             
   DATE (CURRENT_DATE) - DATE ('0001-01-01')       
   FROM SYSIBM.SYSDUMMY1;     


I checked in net and few forums say that '0001-01-01' is a valid date in DB2. Am not sure then why my Cobol Program errors out with SQLCODE -304 when i feed the date as '0001-01-01'

Thanks
Sikkandhar
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Nov 29, 2012 1:13 pm
Reply with quote

Code:
---------+---------+---------+---------+---------+---------+---------+---------+
SELECT                                                                  00000199
   DATE (CURRENT DATE) - DATE ('0001-01-01')                            00000299
   FROM SYSIBM.SYSDUMMY1;                                               00000399
---------+---------+---------+---------+---------+---------+---------+---------+

---------+---------+---------+---------+---------+---------+---------+---------+
 20111028,

Is the output you get

What is the business reason here at first place to subtract a year , a month and a day from a given date??

Can you try ?

Code:
SELECT                                             
   DATE (CURRENT_DATE) - DATE ('0001-01-01')   
   INTO :VAR1   
   FROM SYSIBM.SYSDUMMY1; 
Back to top
View user's profile Send private message
Sikkandhar

New User


Joined: 03 Dec 2007
Posts: 61
Location: Bangalore

PostPosted: Thu Nov 29, 2012 2:13 pm
Reply with quote

The Input date should not exceed specific limit when compared with the Current date.
In one of the cases, the Input date fed was '0001-01-01'. This date should have ideally returned 20111028 (which is beyond a specific limit as per Business Rules). Instead it returns SQLCODE -304

Tried with below code also

Code:
SELECT                                             
    DATE (CURRENT DATE) - DATE (:VAR2) 
INTO :VAR1                             
FROM SYSIBM.SYSDUMMY1         


Where VAR2 has the value '0001-01-01'.
It is still giving me SQLCODE -304
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Thu Nov 29, 2012 2:47 pm
Reply with quote

Sikkandhar,

Read the Error message properly.

Have you verified the table definations.
Quote:
Programmer Response: Verify that table definitions are current, and that
the host variable has the correct data type. See the explanation for
SQLCODE -405 for ranges of SQL data types.


Show us how the :VAR1 is defined in working-storage section.

Thanks,
Sushanth
Back to top
View user's profile Send private message
Sikkandhar

New User


Joined: 03 Dec 2007
Posts: 61
Location: Bangalore

PostPosted: Thu Nov 29, 2012 2:56 pm
Reply with quote

Thanks Sushanth.

I was able to resolve the error. I had defined VAR1 as S9(04) comp. The parameter that was about to be set is beyond the range. Changed the declaration to S9(09) comp and it worked fine
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Need help to append a date&tsp at... DFSORT/ICETOOL 9
No new posts Fetch data from programs execute (dat... DB2 3
Search our Forums:

Back to Top