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

Adding integer to date field - checking for function module

Former Member
1,979

Hi,

I have date field in my internal table,I have one more field temp, it's an integer.

I want to add that integer to that date.

for example.

date1 = 20060719.

temp = 3.

If I add temp to date1 i have to get new_date = 20060722.

Is there any function module availble for this scenario.

Thanks in advance,

fractal

1 ACCEPTED SOLUTION
Read only

Former Member
1,360

You don't need a function module for that. You can add or subtract certain number of days(expressed as integers) from dates. Just make sure that your date variable is of dats type(D) or like sy-datum.

data: v_date like sy-datum value '20060719',

v_newdate like sy-datum.

v_newdate = v_date + 3.

write:/ v_newdate.

v_newdate = v_date - 3.

write:/ v_newdate.

7 REPLIES 7
Read only

hymavathi_oruganti
Active Contributor
0 Likes
1,360

it automatically does that. no extra fn module is needed.

variable should be declared of type D

ex:

execute this and check

data: date type d.

date = sy-datum.

write date.

date = date + 3.

write date.

Read only

Former Member
0 Likes
1,360

Hi fractal,

ABAP handles adding integers to dates seamlessly. The interger is interpreted as a number of days so by just saying (using variables from your example):

new_date = date1 + temp.

you will get the result that you want.

Regards,

Dion

Read only

Former Member
1,361

You don't need a function module for that. You can add or subtract certain number of days(expressed as integers) from dates. Just make sure that your date variable is of dats type(D) or like sy-datum.

data: v_date like sy-datum value '20060719',

v_newdate like sy-datum.

v_newdate = v_date + 3.

write:/ v_newdate.

v_newdate = v_date - 3.

write:/ v_newdate.

Read only

0 Likes
1,360

Hi,

first field is ivbak-audat,

second field is integer = 3.

new_date = ?

thanks,

fractal

Read only

0 Likes
1,360

declare new_date of type d or of type audat

u will get the result u wanted

Read only

0 Likes
1,360

new_date = i_vbak-audat + 3.

But if ivbak-audat is not defined as a date field then move it to a date field and then do the addition.

data: v_date like sy-datum.

move ivbak-audat to v_date.

new_date = v_date + 3.

Read only

Former Member
0 Likes
1,360

Hi,

No function module is reqd. jus declare temp as type D

hope this helps u.

regards,

Seema.