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: 

Determining periods between dates

Former Member
0 Kudos

Hi Friends

This question is regarding determinations of periods between two dates.

For example,

Start date = 01/01/2005

End date = 07/31/2005

I want to populate a internal table, which consists of all months (periods) based on the start date and end date as follows

200501

200502

200503

200504

200505

200506

200507

Is there any standard Function module available to do this? What is the best way to do this?

Thanks

Hari

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Not sure about a function module, but you can do this.



report zrich_0001.

data: begin of isp occurs 0,
      spbup type spbup,
      end of isp.
data: start_date type sy-datum value '20050101'.
data: end_date type sy-datum value '20050731'.

isp-spbup = start_date+0(6).
append isp.

do.

  isp-spbup = isp-spbup + 1.
  if isp-spbup+4(2) = 13.
    isp-spbup+0(4) =  isp-spbup+0(4) + 1.
    isp-spbup+4(2) = '01'.
  endif.

  if isp-spbup <= end_date+0(6).
    append isp.
  else.
  clear isp.
  exit.
  endif.

enddo.

check sy-subrc = 0.

Regards,

Rich Heilman

3 REPLIES 3

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Not sure about a function module, but you can do this.



report zrich_0001.

data: begin of isp occurs 0,
      spbup type spbup,
      end of isp.
data: start_date type sy-datum value '20050101'.
data: end_date type sy-datum value '20050731'.

isp-spbup = start_date+0(6).
append isp.

do.

  isp-spbup = isp-spbup + 1.
  if isp-spbup+4(2) = 13.
    isp-spbup+0(4) =  isp-spbup+0(4) + 1.
    isp-spbup+4(2) = '01'.
  endif.

  if isp-spbup <= end_date+0(6).
    append isp.
  else.
  clear isp.
  exit.
  endif.

enddo.

check sy-subrc = 0.

Regards,

Rich Heilman

Former Member

hi

good

try this function module

HR_PAYROLL_PERIODS_GET Get the payroll period for a particular date.

thanks

mrutyun^

Former Member
0 Kudos

hi Hari,

see the following logic.

report  ysjtest.

data:
     lv_sdate(10),
     lv_edate(10),
     lv_ndate(6),
     lv_month type i,
     lv_endmonth  type i,
     bdate type sy-datum,
     edate type sy-datum.

     lv_sdate = '01/01/2005'.
     lv_edate = '07/31/2005'.
    
     concatenate  lv_sdate+6(4) lv_sdate+0(2) lv_sdate+3(2) into bdate.
     concatenate lv_sdate+6(4) lv_sdate+3(2) into lv_ndate.
     lv_month = lv_sdate+0(2).
     lv_endmonth = lv_edate+0(2).
     write:/ lv_ndate.
    while lv_month < lv_endmonth.
        lv_month = lv_month + 1.
       call function 'OIL_GET_NEXT_MONTH'
       exporting
             i_date = bdate
       importing
            e_date = edate.
      concatenate  lv_sdate+6(4) edate+4(2) lv_sdate+3(2) into bdate.
      concatenate edate+0(4) edate+4(2) into lv_ndate.
      write:/ lv_ndate.  " (or you can append this to internal table, if you want).
endwhile.

Hope this helps.

Sajan.