2006 May 24 4:40 PM
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.
2006 May 24 4:46 PM
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
2006 May 24 4:46 PM
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
2006 May 24 4:50 PM
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.
2006 May 24 4:51 PM
2020 Nov 17 12:13 PM
Is there any standard FM to generate dates if i want monthly or weekly or yearly
2006 May 24 4:48 PM
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
2006 May 24 4:50 PM
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
2006 May 24 4:53 PM
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
2006 May 24 4:57 PM
Hi Srikanth,
I am sorry, I misunderstood your question as months between two dates.
Rich's code is excellent.
Regards,
Vicky
2006 May 24 5:21 PM
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
2006 May 24 6:03 PM
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