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

Function module to add day into date not working

Raxph
Participant
0 Likes
4,122

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!

1 ACCEPTED SOLUTION
Read only

jmodaal
Active Contributor
3,687

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?

5 REPLIES 5
Read only

jmodaal
Active Contributor
3,688

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?

Read only

Sandra_Rossi
Active Contributor
3,687

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
Read only

3,687

DATA(day_after_april_30th) = CONV d( april_30th + 1 ). might be better

Read only

0 Likes
3,687

stefan-de-vriendt thanks

Read only

lemoreno
Participant
3,687

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