2022 Apr 22 4:00 PM
Hi together,
I am trying to add a day to the date, however it is not working with various function module that I have tried. The data is as follows:
DATA: lv_date TYPE vkdfs-fkdat, "The first date that we are getting.
lv_day TYPE knvv-podtg, "The day that we need to add to the above date.
lv_end_date TYPE vkdfs-fkdat. "The final date that is going to be used for other functions.
Now I have tried using several function modules, such as RP_CALC_DATE_IN_INTERVAL and BKK_ADD_WORKINGDAY, however a dump is generated every time as the variable lv_day is of the knvv-podtg type and it has a data type of DEC with length 11.
I have been told not use simple addition, but rather to use function module, as we may have scenarios where the lv_date = 30.04.2022 and lv_day = 1, we may have a result of lv_end_date = 31.04.2022(which is unlogic as April has only 30 days).
Can anyone give a Function Module that can solve my issue?
Thank you all in advance!
2022 Apr 22 4:50 PM
Hello,
>lv_date = 30.04.2022 and lv_day = 1, we may have a result of lv_end_date = 31.04.2022
sure? If you are working with fields of type DATS, adding days should work properly. Using the above given values, the calculation a DATS field with 20220430 + 1 should result in 20220501.
Did you test this?
Hello,
>lv_date = 30.04.2022 and lv_day = 1, we may have a result of lv_end_date = 31.04.2022
sure? If you are working with fields of type DATS, adding days should work properly. Using the above given values, the calculation a DATS field with 20220430 + 1 should result in 20220501.
Did you test this?
2022 Apr 22 4:50 PM
Hello,
>lv_date = 30.04.2022 and lv_day = 1, we may have a result of lv_end_date = 31.04.2022
sure? If you are working with fields of type DATS, adding days should work properly. Using the above given values, the calculation a DATS field with 20220430 + 1 should result in 20220501.
Did you test this?
2022 Apr 22 6:56 PM
Same answer as Jan + example.
I guess you have been wrongly advised. Probably you've been told about adding 1 to 30 the same way as numbers would give 31, but ABAP has special processing with dates, so use this feature.
DATA(april_30th) = CONV d( '20220430' ).
DATA(day_after_april_30th) = CONV d( april_30th + 1 ).
ASSERT day_after_april_30th = CONV d( '20220501' ). " <=== always true
2022 Apr 23 8:12 PM
DATA(day_after_april_30th) = CONV d( april_30th + 1 ). might be better
2022 Apr 24 6:35 AM
2022 Apr 22 7:06 PM
Hi Raxophord,
There are a lot of FM to calculate dates, however, each one has its own input parameters that you have to send to generate the new date.
For example, the FM RP_CALC_DATE_IN_INTERVAL has a parameter to increase the days, it is called DAYS and it is NUMC 2.
If you are going to use a FM to calculate a date, you have to use the same type parameters, so, in the previous FM that i mentioned, the days parameters must be numc 2.
For this purpose, you can create a new variable with the same type, then, you can use the FM with the same parameter type.
DATA: days TYPE t5a4a-dlydy.
days = lv_day.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = lv_date
days = days
months = month
signum = '+'
years = year
IMPORTING
calc_date = lv_end_date.It can works if the number in the lv_day variable is up to 99, if it is greater than that, you can try to convert the number in months or years.
Hope it helps.
Greetings.
Esteban
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |