Application Development 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: 

Method help !!

Former Member
0 Kudos
292

hi experts,

Can anyone help in writing the method for the below requirement.

Ex:

OldDate: 03/10/1992

Current Date:09/24/2008

Calculation : (difference between the two dates) / 365 = 6042 / 365 = 16.55 (rounded to the second decimal place)

I tried with the below code. Not sure if it is right.

METHOD NoOfDays.

DATA: employerServiceDate TYPE sy-datum,

noofdays TYPE i,

l_year TYPE char4,

l_mm TYPE char2,

l_dd TYPE char2,

l_diff_days TYPE d.

CLEAR :l_year,l_mm,l_dd,values,l_diff_days,employerServiceDate.

l_mm = employerServiceDate(2).

l_dd = employerServiceDate+3(2).

l_year = employerServiceDate+6(4).

CONCATENATE l_year l_mm l_dd INTO employerServiceDate.

l_diff_days = (sy-datum - employerServiceDate)/365.

values = l_diff_days.

ENDMETHOD.

Thanks

Ramani

5 REPLIES 5

Former Member
0 Kudos
165

Hi Ramani,

What is your expected output?

16.55 should be ___?___ .

Regards,

R.Nagarajan.

0 Kudos
165

Yes the expected O/p should be 16.55

Thanks

Ramani

0 Kudos
165

Other Way would be,

DATA: lv_old TYPE datum VALUE '19920310',
      lv_curr TYPE datum VALUE '20080924',
      lv_diff LIKE p0347-scrdd,
      lv_bal  TYPE p DECIMALS 2.

lv_diff = lv_curr - lv_old.

lv_bal = lv_diff / 365.

WRITE:/ lv_bal.

Former Member
0 Kudos
165

See the results of this code.

DATA: lv_old TYPE datum VALUE '19920310',
      lv_curr TYPE datum VALUE '20080924',
      lv_diff LIKE p0347-scrdd,
      lv_bal  TYPE p DECIMALS 2.


CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
  EXPORTING
    date1                   = lv_curr
    date2                   = lv_old
    output_format           = '02'
  IMPORTING
    days                    = lv_diff
  EXCEPTIONS
    invalid_dates_specified = 1
    OTHERS                  = 2.

lv_bal = lv_diff / 365.

WRITE:/ lv_bal.

Aman

Former Member
0 Kudos
165

answered