Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to add days to date in COBOL-DB2 program

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
mflax

New User


Joined: 01 Sep 2006
Posts: 17
Location: Delhi

PostPosted: Fri Sep 01, 2006 10:24 am    Post subject: How to add days to date in COBOL-DB2 program
Reply with quote

I have some req in cobol and I've to add some days to a julian date.

ex.
Date 9(7)- 2005360 (360th day of 2005)
Day S9(3) - +010
Result 9(7)- 2006005 means (5th day of 2006)

I can hardcode the logic to the program, but I was looking for if there is any function in cobol where I can give inputs as DATE and DAY and I can get output date.

Thanks all for helping me in advance.
Back to top
View user's profile Send private message

sarunkumaar

New User


Joined: 31 Aug 2006
Posts: 15
Location: Chennai, India

PostPosted: Fri Sep 01, 2006 10:36 am    Post subject: How to add days to date ?
Reply with quote

Is it a COBOL-DB2 program or a simple COBOL program ? Suppose if it's a COBOL-DB2 program then functions are there to add days to date ?
Back to top
View user's profile Send private message
mflax

New User


Joined: 01 Sep 2006
Posts: 17
Location: Delhi

PostPosted: Fri Sep 01, 2006 10:40 am    Post subject: Re: How to add days to date ?
Reply with quote

Thanks for reply. It is a COBOL-DB2 program.

What functions can be added ?
Back to top
View user's profile Send private message
sarunkumaar

New User


Joined: 31 Aug 2006
Posts: 15
Location: Chennai, India

PostPosted: Fri Sep 01, 2006 11:19 am    Post subject: How to add days to date ?
Reply with quote

First convert the Julian date to normal date format i.e to YYYY-MM-DD. Then you can add/subract days using following query.


SELECT :WS-DATE + 10 DAY
FROM SYSIBM.SYSDUMMY1;

Where WS-DATE is the Host variable having value of converted date.

I quess you may have some routine to do the date conversion in your system.
Back to top
View user's profile Send private message
sarunkumaar

New User


Joined: 31 Aug 2006
Posts: 15
Location: Chennai, India

PostPosted: Fri Sep 01, 2006 11:53 am    Post subject: How to add days to date ?
Reply with quote

JULIAN_DAY function is there to convert from Gregorian to Julian format. I am not sure whether a function available to do vice-versa in DB2.
Back to top
View user's profile Send private message
mflax

New User


Joined: 01 Sep 2006
Posts: 17
Location: Delhi

PostPosted: Sat Sep 02, 2006 2:00 am    Post subject: Re: How to add days to date ?
Reply with quote

ok, if I have converted date from Julian to normal format such as YYYY-MM-DD then what query I need to write to add some specific number of days.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Sep 02, 2006 7:59 pm    Post subject:
Reply with quote

If you want to do it w/o DB2 use:

INTEGER-OF-DAY, add 10 to the integer then DAY-OF-INTEGER

I think your 1st instict was best. Hard code it. The IFs or DB2 add a lot of O'head. But don't forget the the leap year.

On the other hand, if you only do it once in the pgm it doesn't matter.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Wed Sep 06, 2006 7:17 am    Post subject: Re: How to add days to date ?
Reply with quote

Hi mmwife,

No contradictions to you... just curious to know why do hard coding can be a better approach than Cobol Functions here... because are not we avoiding leap years calculations by using functions here...
Back to top
View user's profile Send private message
sumansyed

New User


Joined: 05 Apr 2005
Posts: 1

PostPosted: Wed Sep 06, 2006 8:59 am    Post subject:
Reply with quote

Hi mflax,

If you can get the date converted.
Query provided by our friend sarunkumaar will serve the purpose.

Please correct if i am wrong.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Sep 07, 2006 3:46 am    Post subject:
Reply with quote

Hi Priyesh,

Of course it depends on the situation, but some these COBOL supplied functions come with substantial ohead. Many invoke programs and they are usually generalized to handel a wide variety of situations.

Sometimes looking at the generated assembler code will give you a feel for the kind of ohead involved, But here I think you'll find a call to another pgm is involved.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Thu Sep 07, 2006 8:37 am    Post subject: Re: How to add days to date ?
Reply with quote

Thanks Much mmwife...
Quote:
Of course it depends on the situation, but some these COBOL supplied functions come with substantial ohead. Many invoke programs and they are usually generalized to handel a wide variety of situations.

Actually I was also involved in such stuff few days back when I used INTEGER-OF-DATE & DATE-OF-INTEGER for such DATE ARITHMETIC.
Thats why was more curious to know about it.

anyway, seems MFLAX would have got the answer till now... Isn't it ?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts COBOL Code Parsers and Lineage Establ... balimanja COBOL Programming 2 Tue May 02, 2017 3:30 am
No new posts Cobol upgrade - source code missing f... gthmrj IBM Tools 1 Wed Apr 26, 2017 6:04 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us