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

calculate average for some dates

Former Member
0 Likes
1,218

Hi,

I would like to calculate average for some dates. Is there any function module or any process, please provide me.

venkat.

Hi,

I would like to calculate average for some dates. Is there any function module or any process, please provide me.

venkat.

4 REPLIES 4
Read only

Former Member
0 Likes
828

Hi,

Function module: HR_HK_DIFF_BT_2_DATES

Also check http://abaplovers.blogspot.com/2008_04_30_archive.html

Read only

Former Member
0 Likes
828

Hi,

Check this code...is it what your are looking for

data : l_date1 type sy-datum value '20090401'.
data : l_date2 type sy-datum value '20090430'.
data : l_date3 type sy-datum.

l_date3 = ( l_date1 + l_date2 ) / 2.
Write :/ l_date1, l_date2, l_date3.

Read only

Former Member
0 Likes
828

Use this FM HR_HK_DIFF_BT_2_DATES

Example:

DATA: DATE1 type P0001-BEGDA,

DATE2 type P0001-BEGDA,

YEARS type P0347-SCRYY,

MONTHS type P0347-SCRMM,

DAYS type P0347-SCRDD.

DATE1 = '20070331'.

DATE2= '20070101'.

CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

EXPORTING

DATE1 = date1

DATE2 = date2

OUTPUT_FORMAT = '03'

IMPORTING

YEARS = years

MONTHS = months

DAYS = days

  • EXCEPTIONS

  • INVALID_DATES_SPECIFIED = 1

  • OTHERS = 2

.

IF SY-SUBRC 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Regards,

Joan

Read only

Former Member
0 Likes
828

What you can do is find the difference in dates using function module.

SD_CALC_DURATION_FROM_DATETIME

Here you would get duration in hours

Just divide it by 24 to get number of days.

And divide this by 2 to get the mid value ...

This number of days you can add to the smaller date using function module.

RP_CALC_DATE_IN_INTERVAL

Hope this helps you ...

Regards,

Lalit Mohan Gupta.