2021 Feb 27 9:20 PM
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
2021 Feb 27 9:43 PM
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.
2021 Feb 27 9:43 PM
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.
2021 Feb 28 8:22 AM
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.