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: 

Dates between 2 given dates

Former Member
0 Kudos

hi,

i want to know is there any function module which will return all the dates between the given range of dates.

example : if i give 20/01/2006 and 25/01/2006 it should return 20/01/2006,21/01/2006,22/01/2006,23/01/2006,24/01/2006,25/01/2006.

regards

Srikanth Kidambi.

Intelligroup.

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Please check this sample program.



report zrich_0001.

data: begin_date type sy-datum value '20060110',
      end_date type sy-datum value '20060125'.

data: idatum type table of sy-datum with header line.

idatum = begin_date.
append idatum.

do.
  if idatum  = end_date.
    exit.
  endif.
  idatum =  idatum + 1.
  append idatum.
enddo.


loop at idatum.

  write:/ idatum.
endloop.

Regards,

Rich Heilman

10 REPLIES 10

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Please check this sample program.



report zrich_0001.

data: begin_date type sy-datum value '20060110',
      end_date type sy-datum value '20060125'.

data: idatum type table of sy-datum with header line.

idatum = begin_date.
append idatum.

do.
  if idatum  = end_date.
    exit.
  endif.
  idatum =  idatum + 1.
  append idatum.
enddo.


loop at idatum.

  write:/ idatum.
endloop.

Regards,

Rich Heilman

0 Kudos

Hi,

logic provided by Rich is really good one.

ABAP automatically calculates the next date.

Do need to worry if the data type is DATS.

Core data type for date is DATS.

0 Kudos

hi Srikanth,

Check these FM <b>RS_VARI_V_DAYS_UP_TO_NOW</b>

0 Kudos

Is there any standard FM to generate dates if i want monthly or weekly or yearly

Former Member
0 Kudos

I am not aware of any function that gives the dates as such, but there is one that gives the days.

In you case probably you can write a custom function and inside the increment the starting date by till you reach the end date and return all the dates in a internal table.

Regards,

Ravi

Note : Please mark the helpful answers

Former Member
0 Kudos

Hi Srikanth,

I think you can use FM 'MONTHS_BETWEEN_TWO_DATES' and then increment month to get required value.

Hope this will help you.

Regards,

Vicky

Former Member
0 Kudos

Hi Srikanth,

check the below logic

Logic is :

Calculate in a loop using +1.

*----


REPORT abc.

*----


DATA : BEGIN OF itab OCCURS 0,

mydate TYPE sy-datum,

END OF itab.

SELECT-OPTIONS budat FOR sy-datum OBLIGATORY.

*----


END-OF-SELECTION.

PERFORM get_all_dates.

LOOP AT itab.

WRITE / itab-mydate.

ENDLOOP.

*----


FORM get_all_dates.

CLEAR itab.

REFRESH itab.

DATA : myctr TYPE i.

DATA : newdate TYPE sy-datum.

newdate = budat-low.

*----


Loop And Generate Dates

DO.

IF newdate <= budat-high.

itab-mydate = newdate.

APPEND itab.

ELSE.

itab-mydate = sy-datum.

EXIT.

ENDIF.

newdate = newdate + 1.

ENDDO.

ENDFORM. "get_all_dates

Regards,

Naveen

Former Member
0 Kudos

Hi Srikanth,

I am sorry, I misunderstood your question as months between two dates.

Rich's code is excellent.

Regards,

Vicky

Former Member
0 Kudos

hi Rich,

the logic is excellent.but one problem with that logic is it wont exclude the country specific holidays.

Mean while i too tried to find out the function module and i succeeded in getting it.

here it is, "RKE_SELECT_FACTDAYS_FOR_PERIOD". this also gives all the given dates between 2 given dates excluding the country specific holidays(it is having the FactoryID field)

Any how,Thanks for giving good logic.

regards

srikanth

0 Kudos

Oh, If you had mentioned that you want only working days, then I would have went a slightly different way.



report zrich_0001.

data: begin_date type sy-datum value '20060110',
      end_date type sy-datum value '20060125'.

data: idatum type table of sy-datum with header line.
data: indicator type scal-indicator.

idatum = begin_date.
append idatum.

do.
  if idatum  = end_date.
    exit.
  endif.



  idatum =  idatum + 1.


  call function 'DATE_CONVERT_TO_FACTORYDATE'
       exporting
            date                 = idatum
            factory_calendar_id  = 'P6'
       importing
            workingday_indicator = indicator
       exceptions
            others               = 7.

  if indicator = space.
    append idatum.
  endif.

enddo.

loop at idatum.
  write:/ idatum.
endloop.

Regards,

Rich Heilman