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

Incorrect month value between 2 dates with Function Module FIMA_DAYS_AND_MONTHS_AND_YEARS

0 Kudos
2,439

Hi all,

I´m using the SAP standard Function Module FIMA_DAYS_AND_MONTHS_AND_YEARS to calculate the difference in months between two dates.

While calculating the month difference with input parameter I_DATE_FROM as 28.02. (in case of not a leap year, e.g. 2021, 2022, 2023) or 29.02 (in case of a leap year, e.g. 2016, 2020, etc.) and 31.03 as an I_DATE_TO input parameter I´m facing the not as expected result for the export parameter E_MONTHS. With 30.03. as example I_DATE_TO the month value is calculated as expected.

1.) Not a leap year case:

1a) Positive Example (as expected):

- I_DATE_FROM: 28.02.2021
- I_DATE_TO: 30.03.2021
- E_MONTHS: 2 (as expected)
- I_FLG_ROUND_UP: X

1b) Negative Example (not as expected):

- I_DATE_FROM: 28.02.2021
- I_DATE_TO: 31.03.2021
- E_MONTHS: 1 (not as as expected, instead 2 months are expected)
- I_FLG_ROUND_UP: X

2.) Leap year case:

2a) Positive Example (as expected):

- I_DATE_FROM: 29.02.2020
- I_DATE_TO: 30.03.2020
- E_MONTHS: 2 (as expected)
- I_FLG_ROUND_UP: X

2b) Negative Example (not as expected):

- I_DATE_FROM: 29.02.2020
- I_DATE_TO: 31.03.2020
- E_MONTHS: 1 (not as as expected, instead 2 months are expected)
- I_FLG_ROUND_UP: X

Any ideas?

Thank you in advance.

Best regards,
Michael

1 ACCEPTED SOLUTION
Read only

BiberM
Active Participant
2,108

The problem are ultimo days. Additionally you can't supply a day count method. So it automatically decides whether both dates are ultimo. If that is the case the difference is exactly one month (actual/actual). So no need to round up.

If you specify one of the dates as non ultimo the system assumes that you need to calculate from the actual date: 28.02. to 28.03. is one month and to the 30.03. are two more days. Rounded up this result in 2 months difference.

2 REPLIES 2
Read only

BiberM
Active Participant
2,109

The problem are ultimo days. Additionally you can't supply a day count method. So it automatically decides whether both dates are ultimo. If that is the case the difference is exactly one month (actual/actual). So no need to round up.

If you specify one of the dates as non ultimo the system assumes that you need to calculate from the actual date: 28.02. to 28.03. is one month and to the 30.03. are two more days. Rounded up this result in 2 months difference.

Read only

0 Kudos
2,108

Thanks for the explanation related to the ultimo problem and the recommendation to specify one of the dates as non ultimo day. I added now in my function module in which I´m reusing the function module FIMA_DAYS_AND_MONTHS_AND_YEARS a pre-check with the help of the function module FIMA_END_OF_MONTH_DETERMINE to check if my I_DATE_FROM is a ultimo day (last day of a month), e.g. 29.02.2020, 28.02.2021, etc. If I_DATE_FROM is a ultimo day, specify it as a non ultimo day by subtracting one day, if I_DATE_FROM is not on a ultimo day take it as it is. With specifying I_DATE_FROM as non ultimo day, if it´s as per the check on a ultimo day, the result for E_MONTHS is now, within my function module, with the help of the reused function module FIMA_DAYS_AND_MONTHS_AND_YEARS calculated as expected.