Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
manikandanjs

New User

Joined: 02 Jun 2006
Posts: 27
Location: Blue Bell, PA

 Posted: Tue Dec 26, 2006 2:58 pm    Post subject: How to calculate the date prior to 13 months Hi, I need to calculcate the date prior to 13 monts from the current date. I need to implement this in a COBOL program. Could you please say any way to do this? Thanks Manikandan J

William Thompson

Global Moderator

Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

Posted: Tue Dec 26, 2006 3:35 pm    Post subject: Re: How to calculate the date prior to 13 monts

 manikandanjs wrote: I need to calculcate the date prior to 13 monts from the current date. I need to implement this in a COBOL program. Could you please say any way to do this?
There are several intrinsic date functions available.
How are you defining 13 months? 13 calendar months? 1 year and 1 month? 390 days?
manikandanjs

New User

Joined: 02 Jun 2006
Posts: 27
Location: Blue Bell, PA

 Posted: Tue Dec 26, 2006 5:24 pm    Post subject: Re: How to calculate the date prior to 13 monts Hi, I need to calculate with 13 calendar months. Thanks Manikandan J
William Thompson

Global Moderator

Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

 Posted: Tue Dec 26, 2006 5:32 pm    Post subject: Hi Manikandan, For 13 calendar months the simplest would be: If mm = 01 mm = 12 subtract 2 from yy else subtract 1 from mm subtract 1 from yy end-if If the yy field can get near 2000, you could replace the yy subtraction with a check and replace like the IF statement does for the mm subtraction. Hope this helps, Bill
manikandanjs

New User

Joined: 02 Jun 2006
Posts: 27
Location: Blue Bell, PA

 Posted: Tue Dec 26, 2006 5:47 pm    Post subject: Re: How to calculate the date prior to 13 monts Hi, Thanks for your quick turn around, but in the above case we can calculate only the month that has to be 13 months before. Take a case where the curent date falls under 12/31/2006(MM/DD/YYYY) then the date before 13 month should be 11/31/2005 which is invalid but the expected result is 12/01/2005, the same case will be applicable for any months which has 31 days and the date falls on 31st. The same problem persists for Mar 29,30 and 31. Let me know the solution for the above mentioned scenario. Thanks, Manikandan J
William Thompson

Global Moderator

Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

Posted: Tue Dec 26, 2006 6:19 pm    Post subject: Re: How to calculate the date prior to 13 monts

 manikandanjs wrote: Take a case where the curent date falls under 12/31/2006(MM/DD/YYYY) then the date before 13 month should be 11/31/2005 which is invalid but the expected result is 12/01/2005, the same case will be applicable for any months which has 31 days and the date falls on 31st. The same problem persists for Mar 29,30 and 31.

 Code: evaluate mm    when 02       evaluate dd          when 31             mm = 03             dd = 01          when 30             mm = 03             dd = 02          when 29 * leap year logic goes here             mm = 03             dd = 03       end-evaluate    when 04       evaluate dd          when 31             mm = 05             dd = 01       end-evaluate    when 06       evaluate dd          when 31             mm = 07             dd = 01       end-evaluate    when 09       evaluate dd          when 31             mm = 10             dd = 01       end-evaluate    when 11       evaluate dd          when 31             mm = 12             dd = 01       end-evaluate end evaluate

I think the syntax is ok....There is another was I'll post next.
priyesh.agrawal

Senior Member

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

Posted: Tue Dec 26, 2006 10:58 pm    Post subject: Re: How to calculate the date prior to 13 monts

manikandanjs...

I would prefer to code a simple SQL instead of coding whole the logic in COBOL statements...
 Code: SELECT CURRENT_DATE - 13 MONTHS   FROM SYSIBM.SYSDUMMY1;

And you should not have problems coding it inside your program... would you ?
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19254
Location: Inside the Matrix

Posted: Wed Dec 27, 2006 12:46 am    Post subject:

Hello,

 Quote: Take a case where the curent date falls under 12/31/2006(MM/DD/YYYY) then the date before 13 month should be 11/31/2005 which is invalid but the expected result is 12/01/2005, the same case will be applicable for any months which has 31 days and the date falls on 31st. The same problem persists for Mar 29,30 and 31.

Why is the expected result 12/01? In many cases, the expected result for many would be as follows:

From date: Sunday, December 31, 2006
Subtracted 13 months

Normalized to 1 year, 1 month
Resulting date: Wednesday, November 30, 2005

This result is from http://www.timeanddate.com/date/dateadd.html which is a free online date calculator.

March 30 yields this:
From date: Thursday, March 30, 2006
Subtracted 13 months

Normalized to 1 year, 1 month
Resulting date: Monday, February 28, 2005

If you "go back" 13 months is will most always be the previous month last year - shifted to the end of that month when necessary.

 Quote: I would prefer to code a simple SQL instead of coding whole the logic in COBOL statements...

This works well if the code already does SQL. If not . . . .

Many of the sites i support have written their own routine to perform date arithmetic - taking into account the organization's date rules. I'd suggest you compare your expectations to the results given by SQL as well as any other date routines available at your installatoin.
trgk03

New User

Joined: 20 Jan 2006
Posts: 12
Location: kochi

 Posted: Wed Dec 27, 2006 12:10 pm    Post subject: Hi manikandanjs, Plz find out if you have some inbuilt subroutine in ur company.Normally professional cobol programmers use these subroutines for very complex date calculation which would otherwise take weeks to complete. Cheers, sD
manikandanjs

New User

Joined: 02 Jun 2006
Posts: 27
Location: Blue Bell, PA

 Posted: Wed Dec 27, 2006 2:36 pm    Post subject: Re: How to calculate the date prior to 13 monts Hi, In our environment we don't have DB2. We are using only CICS and VSAM model. I'm not able to compile the program if i include the SQL code as the compiler is asking for Package and Plan (which we don't have). Could you let me know some other idea. thanks Manikandan J
William Thompson

Global Moderator

Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

Posted: Wed Dec 27, 2006 3:05 pm    Post subject: Re: How to calculate the date prior to 13 monts

 manikandanjs wrote: In our environment we don't have DB2. We are using only CICS and VSAM model.
Well, scratch that...
 Quote: Could you let me know some other idea.
How are you going to deal with dick scherrer's comments?
If you can define the rules for which 13 month old date you want, then just code your program for those rules.
what else are you expecting?
manikandanjs

New User

Joined: 02 Jun 2006
Posts: 27
Location: Blue Bell, PA

 Posted: Thu Dec 28, 2006 10:15 am    Post subject: Re: How to calculate the date prior to 13 monts Hi, I do agree with dick scherrer's comment and example. It should behave like that only. Just want to know that is there any system function avilable in COBOL to get the exact date prior to 13 months. Thanks Manikandan J
priyesh.agrawal

Senior Member

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

Posted: Thu Dec 28, 2006 11:33 am    Post subject: Re: How to calculate the date prior to 13 monts

 Quote: Just want to know that is there any system function avilable in COBOL to get the exact date prior to 13 months.

No such Intrinsic Function available with COBOL for date arithmatic.
 Quote: In our environment we don't have DB2. We are using only CICS and VSAM model. I'm not able to compile the program if i include the SQL code as the compiler is asking for Package and Plan (which we don't have). Could you let me know some other idea.

If you dont have at all, Sorry !!!
Else a JCL step could also be coded to fire this query and resultent dataset can be formatted to have only OUTPUT-DATE which in turn can be passed to your program... Pls excuse me, if sounds weired...
William Thompson

Global Moderator

Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

Posted: Thu Dec 28, 2006 2:55 pm    Post subject: Re: How to calculate the date prior to 13 monts

 manikandanjs wrote: Just want to know that is there any system function available in COBOL to get the exact date prior to 13 months.
The intrinsics integer of date and date of integer might work, the FM says no but I have a very old memory of using this type of function to fix the date. Given the date 11/31/2006 it would convert it into an integer and given that integer, it would convert back to 12/01/2006....COBOL? SQL? Excel? I just can't recall exactly....
smile_rajeev

New User

Joined: 22 Apr 2005
Posts: 24

 Posted: Thu Dec 28, 2006 3:30 pm    Post subject: Re: How to calculate the date prior to 13 monts hi mani, I hope the below could help u out for ur problem. i also had the same requirement in my current project. i have to find the start date which is six month prior to the current date. I have replaced the value 6 by 13 for ur case. i hope by using this code u can get the exact month and year .. but to calculate the days i need some more information from u. I this code i have moved 1 for date... But cud u give some examples of current date ( for month december, april, etc) and expeected dates so that i can try my level best to resolve ur problem. Date variables ------------------- WS-RPT-RUN-- current date for year,month,day WS-ACTMEMB-START---13 month prior date MOVE 1 TO WS-ACTMEMB-START-DD COMPUTE WS-TEMP-MM = WS-RPT-RUN-MM - 13 IF WS-TEMP-MM IS NEGATIVE COMPUTE WS-ACTMEMB-START-YYYY = WS-RPT-RUN-YYYY - 1 MOVE WS-TEMP-MM TO WS-FMT-TEMP-MM COMPUTE WS-ACTMEMB-START-MM = 12 - WS-FMT-TEMP-MM ELSE MOVE WS-TEMP-MM TO WS-ACTMEMB-START-MM MOVE WS-RPT-RUN-YYYY TO WS-ACTMEMB-START-YYYY END-IF. To calculate date u need to check for leap years. Thanks Rajeev
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19254
Location: Inside the Matrix

 Posted: Thu Dec 28, 2006 9:01 pm    Post subject: Hello, In addition to leap year considerations, you will also need to make sure the date resulting from the calculation is possible (for example SEP 31, FEB 30, etc.) can NOT be valid and will need to be adjusted.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics reffering the filename with date and ... skbk JCL & VSAM 1 Sat Jun 06, 2020 4:57 pm Compare input date as YYMMDD with the... Khurshid_Khan SYNCSORT 5 Fri Feb 21, 2020 10:28 pm How to compare Packed date in details... Floramq SYNCSORT 5 Sun Jan 05, 2020 7:40 am Mainframe datasets without any last r... rajatbagga All Other Mainframe Topics 1 Tue Sep 24, 2019 8:47 am Date insertion returns -180 Raghu navaikulam CICS 1 Mon Jul 29, 2019 5:12 pm

 © 2003-2020 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us