Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Leap year issue

Former Member
0 Likes
2,188

Hi friends,

I have a problem in one of the existing codes.

The cancellation amount is calculated for a range of dates.

Say the active line item has a start date of 01.03.2006 and end date of 01.03.2012 say (B).

Now if a rejection/Cancellation is put on date 01.05.2007 (A), the current program is calculating a value

based on the diffrence of days (B - A).

then this cancelled amnt = the no of cancelled days * (a constn value * 12 / 365).

Now I want to modify my logic in such a way that the leap is also accounted.

If I use the same dates , i realise that 2008 is the leap yr.

So how can i modify my calculation for the range if it contains a leap yr.

Please suggest something on this, as it will be really helpful.

Thanks,

Sapna Agarwal

Hi friends,

I have a problem in one of the existing codes.

The cancellation amount is calculated for a range of dates.

Say the active line item has a start date of 01.03.2006 and end date of 01.03.2012 say (B).

Now if a rejection/Cancellation is put on date 01.05.2007 (A), the current program is calculating a value

based on the diffrence of days (B - A).

then this cancelled amnt = the no of cancelled days * (a constn value * 12 / 365).

Now I want to modify my logic in such a way that the leap is also accounted.

If I use the same dates , i realise that 2008 is the leap yr.

So how can i modify my calculation for the range if it contains a leap yr.

Please suggest something on this, as it will be really helpful.

Thanks,

Sapna Agarwal

8 REPLIES 8
Read only

Former Member
0 Likes
1,362

Hi Sapna,

Instead of using the B-A concept for calculating the date difference use the function module " /SDF/CMO_DATETIME_DIFFERENCE " which gives the difference between two dates and this also takes the leap year into consideration.

Hope this will solve your problem.

Regards Madhu.

Read only

Former Member
0 Likes
1,362

HI,

use this function module.

/SAPNEA/JSC_LEAP_YEAR.

Regards,

Naresh.

Read only

Former Member
0 Likes
1,362

Hi,

Try this: HR_99S_INTERVAL_BETWEEN_DATES

Refer:

Read only

Former Member
0 Likes
1,362

Hi,

you can use the FM HR_HK_DIFF_BT_2_DATES with output_format = '02' to get the difference between dates in days.

Regards

Read only

Former Member
0 Likes
1,362

Hi,

Try using any of these function modules LEAP_DAYS_BETWEEN_TWO_DATES' or FIMA_LEAP_DAYS_BETWEEN_2_DATES.

Or try using this simple logic to find if a date is leap or not..

DATA: date1 TYPE d.

date1 = '20040301'.

date1 = date1 - 1.

IF date1+6(2) = '29'.

WRITE 'A leap year'.

ELSE.

WRITE 'No leap year'.

ENDIF.

Regards

Vasavi Kotha

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
1,362

Hi Sapna,

Use link:-

Hope this solves your problem.

Thanks & Regards,

Tarun Gambhir

Read only

Former Member
0 Likes
1,362

Hello friends,

Thanks for the response on my issue.

The leap year is not the only issue I am facing.

The calculation discussed:

then this cancelled amnt = the no of cancelled days * (a constn value * 12 / 365).

Will also need a change now.

Because if the the division by 365 will be now 366 for a leap year.

But if this is for a range of 2 or 3 yrs in which 1 yr is a leap yr and the other 2 are non leap yrs, then how can i do the calculation.

Regards,

Sapna

Read only

Former Member
0 Likes
1,362

Hi Sapna,

try to use the FM /SDF/CMO_DATETIME_DIFFERENCE, it will take care of the leap year, just pass the two dates for which you want the difference.

CALL FUNCTION '/SDF/CMO_DATETIME_DIFFERENCE'
 EXPORTING
   DATE1                   = s_date
*   TIME1                  =
   DATE2                   = e_date
*   TIME2                  =
 IMPORTING
   DATEDIFF                = DATEDIFF
*   TIMEDIFF               =
*   EARLIEST               =
 EXCEPTIONS
   INVALID_DATETIME        = 1
   OTHERS                  = 2

IF sy-subrc <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

if the gap is for more one year than you have to do the calculation year wise only, in this case use the fm '/SAPNEA/JSC_LEAP_YEAR' that which year is a leap year. And than go for a IF condition while calculating either it should be 365 or 366 days.

With luck,

Pritam.