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

Author Message
arvind.m

Active User

Joined: 28 Aug 2008
Posts: 205

Posted: Mon Jul 13, 2009 2:02 pm    Post subject: Logic is to check for leap year

Hi All,

The below logic is to check for leap year. but there is some problem in the below problem. even for 2007, the logic is going to "NOT ON SIZE ERROR" which is wrong. I'm using Enterprise COBOL. is the version of cobol has to do anything with the above mentioned problem.

 Code: 05  WS-TEST-YEAR             PIC 9(04)     VALUE ZEROS. *** *** IF WS-MED-DATE-MM = 02                             COMPUTE WS-TEST-YEAR  =  WS-MED-DATE-YYYY                             /  4                        ON SIZE ERROR                                     MOVE 28          TO  WS-MED-DATE-DD          NOT ON SIZE ERROR                                 MOVE 29          TO  WS-MED-DATE-DD       END-COMPUTE

Anuj Dhawan

Senior Member

Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

Posted: Mon Jul 13, 2009 5:12 pm    Post subject:

Code is behaving the way it was told to, from the Manuals:
 Quote: ON SIZE ERROR statement1 Statement1 is replaced by the statement(s) that are to be executed whenever a SIZE ERROR condition occurs (i.e., whenever the integer portion of the result of the arithmetic operation exceeds the largest value that can be contained in the integer portion of the recieving field).
In your case WS-MED-DATE-YYYY = 2007 so WS-MED-DATE-YYYY / 4 = 501.75, integer part is less than 9999 (pic 9(4)), so there is NO ON SIZE ERROR.
dick scherrer

Site Director

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

 Posted: Tue Jul 14, 2009 12:22 am    Post subject: Hello, Said slightly differently, you have chosen an incorrect way to check for leap year. With only a simple divide, there are conditions that are not met when determining leap year. Suggest you check out the "rules" for determining what is a leap year. Hint - century years and millenium years need special consideration.
Anuj Dhawan

Senior Member

Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

Posted: Tue Jul 14, 2009 11:28 am    Post subject:

 Quote: the logic is going to "NOT ON SIZE ERROR" which is wrong.
This is not the correct logic to find out a leap-year, so if the control is going to "NOT ON SIZE ERROR" that's not wrong.

Just for fun, here is a C Code :

 Code: #include #include void main() {  int year,leap;  clrscr();  printf("enter the year:-  ");  scanf("%d",&year);  if ((year%100)==0)   leap=(year/400)*400;  else   leap=(year/4)*4;  if (leap==year)   printf(" %d is a leap year.",year);  else   printf(" %d is not a leap year.",year);  getch(); }
arvind.m

Active User

Joined: 28 Aug 2008
Posts: 205

Posted: Tue Jul 14, 2009 11:36 am    Post subject:

Hi Anuj/Dick,

Thank you for you time and help. Actually the code was developed by my client. we have changed the logic after searching in the internet. The issue is resolved but wanted to know the reason.

 Quote: Leap Year Calculation In general terms the algorithm for calculating a leap year is as follows... A year will be a leap year if it is divisible by 4 but not by 100. If a year is divisible by 4 and by 100, it is not a leap year unless it is also divisible by 400. Thus years such as 1996, 1992, 1988 and so on are leap years because they are divisible by 4 but not by 100. For century years, the 400 rule is important. Thus, century years 1900, 1800 and 1700 while all still divisible by 4 are also exactly divisible by 100. As they are not further divisible by 400, they are not leap years.
Anuj Dhawan

Senior Member

Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

 Posted: Tue Jul 14, 2009 1:09 pm    Post subject: A very informal definition is, in the Gregorian calendar, current standard calendar in most of the world, most years that are divisible by 4 are leap years. But in leap year, the month of February has 29 days instead of 28. One extra day is added to compensate for the fact that a period of 365 days is shorter than a solar year by almost 6 hours. When you dig into a bit more, every year has 365.242374 days which are rounded to 365.2425. Decimal part .2400 is rounded to one day (approx.) in every four years and Decimal part .0025 is rounded to one day in every 400 years.
Anuj Dhawan

Senior Member

Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

 Posted: Tue Jul 14, 2009 1:12 pm    Post subject: Why Leap Years Are Used . . . and there is lot more on Google.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Removing the period or dot from the v... gopinak COBOL Programming 6 Wed May 09, 2018 1:53 pm GDG gen check using REXX raghuraman123 CLIST & REXX 6 Wed Apr 18, 2018 9:18 pm How syntax check at Bind time is diff... Poha Eater DB2 5 Wed Mar 21, 2018 9:16 pm Logic to skip Maximum time-stamp and ... vickey_dw DB2 2 Thu Feb 01, 2018 11:15 pm Is CICS BMS logic on z/OS different ... Andi1982 CICS 2 Fri Dec 01, 2017 1:56 pm

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