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

How to calculate the date prior to 13 months


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
manikandanjs

New User


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

PostPosted: Tue Dec 26, 2006 2:58 pm
Reply with quote

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
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Tue Dec 26, 2006 3:35 pm
Reply with quote

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?
More info regarding the actual specifications would be helpful.
Back to top
View user's profile Send private message
manikandanjs

New User


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

PostPosted: Tue Dec 26, 2006 5:24 pm
Reply with quote

Hi,

I need to calculate with 13 calendar months.

Thanks
Manikandan J
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Tue Dec 26, 2006 5:32 pm
Reply with quote

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
Back to top
View user's profile Send private message
manikandanjs

New User


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

PostPosted: Tue Dec 26, 2006 5:47 pm
Reply with quote

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
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Tue Dec 26, 2006 6:19 pm
Reply with quote

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.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


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

PostPosted: Tue Dec 26, 2006 10:58 pm
Reply with quote

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 ?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Dec 27, 2006 12:46 am
Reply with quote

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 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.
Back to top
View user's profile Send private message
trgk03

New User


Joined: 20 Jan 2006
Posts: 12
Location: kochi

PostPosted: Wed Dec 27, 2006 12:10 pm
Reply with quote

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
Back to top
View user's profile Send private message
manikandanjs

New User


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

PostPosted: Wed Dec 27, 2006 2:36 pm
Reply with quote

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
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Wed Dec 27, 2006 3:05 pm
Reply with quote

manikandanjs wrote:
In our environment we don't have DB2. We are using only CICS and VSAM model.
Well, scratch that... icon_sad.gif
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? icon_smile.gif
Back to top
View user's profile Send private message
manikandanjs

New User


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

PostPosted: Thu Dec 28, 2006 10:15 am
Reply with quote

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
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


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

PostPosted: Thu Dec 28, 2006 11:33 am
Reply with quote

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...
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Thu Dec 28, 2006 2:55 pm
Reply with quote

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.... icon_cry.gif
Back to top
View user's profile Send private message
smile_rajeev

New User


Joined: 22 Apr 2005
Posts: 24

PostPosted: Thu Dec 28, 2006 3:30 pm
Reply with quote

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
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Dec 28, 2006 9:01 pm
Reply with quote

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.
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 -> COBOL Programming

 


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 how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
No new posts how to calculate SUM for VB file usin... JCL & VSAM 1
Search our Forums:

Back to Top