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
 

 

Logic is to check for leap year

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

Active User


Joined: 28 Aug 2008
Posts: 205
Location: Hyderabad

PostPosted: Mon Jul 13, 2009 2:02 pm    Post subject: Logic is to check for leap year
Reply with quote

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

Anuj Dhawan

Senior Member


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

PostPosted: Mon Jul 13, 2009 5:12 pm    Post subject:
Reply with quote

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

Site Director


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

PostPosted: Tue Jul 14, 2009 12:22 am    Post subject:
Reply with quote

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

Senior Member


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

PostPosted: Tue Jul 14, 2009 11:28 am    Post subject:
Reply with quote

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 icon_smile.gif :

Code:
#include <stdio.h>
#include <conio.h>
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();
}
Back to top
View user's profile Send private message
arvind.m

Active User


Joined: 28 Aug 2008
Posts: 205
Location: Hyderabad

PostPosted: Tue Jul 14, 2009 11:36 am    Post subject:
Reply with quote

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

Senior Member


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

PostPosted: Tue Jul 14, 2009 1:09 pm    Post subject:
Reply with quote

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

Senior Member


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

PostPosted: Tue Jul 14, 2009 1:12 pm    Post subject:
Reply with quote

Why Leap Years Are Used . . . and there is lot more on Google.
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 Check Binary Values for symbols gandikk CA Products 3 Tue Mar 21, 2017 5:11 am
No new posts SORT to append Month and YEAR in MMYY... tisamf DFSORT/ICETOOL 1 Wed Mar 08, 2017 4:46 pm
No new posts Need help in building a logic Benchwarmer All Other Mainframe Topics 4 Wed Feb 22, 2017 2:49 am
No new posts 2 byte YEAR from Y'DATE2' field tecnokrat DFSORT/ICETOOL 2 Tue Feb 07, 2017 12:05 pm
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 7 Fri Nov 18, 2016 1:48 pm


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