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 get older DATEs in COBOL??

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

New User


Joined: 22 Jul 2008
Posts: 33
Location: Chennai

PostPosted: Mon Nov 23, 2009 1:56 pm    Post subject: How to get older DATEs in COBOL??
Reply with quote

Hi,

I have a requirement where i have to get the previous date, after subtracting a number (which denotes months) from current date.

Eg: If the months number is 24, it means we have to subtract 24 months from the current date (YYYY-MM-DD) and arrive at the old date (YYYY-MMM-DD)

Please let me know if more details are needed
Back to top
View user's profile Send private message

guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Mon Nov 23, 2009 2:10 pm    Post subject:
Reply with quote

Hello Naresh,
Could you please provide an example for i/p & O/p?
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10256
Location: italy

PostPosted: Mon Nov 23, 2009 2:31 pm    Post subject: Reply to: How to get older DATEs in COBOL??
Reply with quote

the issue has been debated quite a few times...

first of all have Your organization define clearly the <algorithm>
... no issues if 1 <= day <= 28 going back two months will not hurt anybody

somebody must clearly define ( from an accounting and legal point of view )
what should be done when subtracting/adding will yield a non existing day

if the program is a db2 program You can use the db2 date/time facilities
in this case when adding subtracting months non existent days will be mapped to the last day of the month

otherwise You will have to write the logic Yourself ...
not very complicated anyway
split the date in the three components year month day
subtract the number of months from the month...
if the result is negative keep adding add 12 to the month and subtract 1 from the year, until positive
if the day is less or equal to the last day of the month ( computed one ) use it,
otherwise use the last day of the month ( computed one )


here is a rexx snippet that will do it ( just to show the logic )
Code:
date = date("S")
tabd = "31 28 31 30 31 30 31 31 30 31 30 31"

do diff = 1 to 24
    date = "20091231"
    parse var date year +4 mnth +2 day
     
    mnth = mnth - diff

    do  while ( mnth <= 0 )
        mnth = mnth + 12
        year = year  - 1
    end

    last = word(tabd,mnth)
    if  mnth = 2 then ,
        last = last + ( (year//400=0)|((year//100<>0 )&(year//4=0)) )
    if  last < day then ,
        day  = last
   
    say date right(diff,2,"0") year || right(mnth,2,"0") || right(day ,2,"0") 

end

exit
Back to top
View user's profile Send private message
nareshkareti

New User


Joined: 22 Jul 2008
Posts: 33
Location: Chennai

PostPosted: Mon Nov 23, 2009 3:57 pm    Post subject:
Reply with quote

I need logic or functions in COBOL

The "month quantity" is taken from a DB2 table and has to subtract from the CURRENT date to give a new date (which is always older dates).

The result should be a valid old date in the correct date format (YYYY-MM-DD)

Say if the month quantity is 2 and current date is 2009-11-23, the result should be 2009-09-23.

I can reformat the logic given in REXX to COBOL, but i just wanted to cross check again.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10256
Location: italy

PostPosted: Mon Nov 23, 2009 5:21 pm    Post subject: Reply to: How to get older DATEs in COBOL??
Reply with quote

look like You did not read/understand my reply...

You implicitly answered one of my questions ...
since the program is already a db2/sql program there will not be any waste/overhead of resources
by using the db2 date computation facilities!

looks like You / Your organization disregarded the fact that monhs have usually each a different number of days...

as I already said ...
the db2 logic in date computations involving addin/subtracting monts is to use the last day of the target month for non existing days

it means that for march 31 going back one month the computed date will be feb 28/29 depending on leapness

have Your organization' s powers formally approve such algorithm/approach
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10256
Location: italy

PostPosted: Mon Nov 23, 2009 6:35 pm    Post subject: Reply to: How to get older DATEs in COBOL??
Reply with quote

follow on...
to explain better my accounting/legal concerns

Quote:
Say if the month quantity is 2 and current date is 2009-11-23, the result should be 2009-09-23.

same subtraction as above
what will be he chosen date on 2010-04-29 2010-04-30

does Your organization realize the issues that might arise ??
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
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
No new posts COBOL Programming Sandpit? jodrisco COBOL Programming 6 Wed Apr 12, 2017 3:47 am


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