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

Date Range

Former Member
0 Likes
635

How can we get all the dates between a given date range (given From Date & To Date) ? Is there any function module to do the same?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
598

Hello,

U could use this code to get the dates.

1. I have created a sample program for your requirement,

and also tested it. Its working fine.

2. 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

If useful reward.

Vasanth

4 REPLIES 4
Read only

Former Member
0 Likes
599

Hello,

U could use this code to get the dates.

1. I have created a sample program for your requirement,

and also tested it. Its working fine.

2. 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

If useful reward.

Vasanth

Read only

0 Likes
598

That was a gr8 logic.. sy-datum + 1... ( 30/31/28 etc everything will be taken care of!) thnx a lot

Read only

Former Member
0 Likes
598

Try this:

do.

if v_date = v_todate.

exit.

else.

v_date = v_fromdate + 1.

write:/ v_date.

endif.

endo.

Regards,

Ravi

Read only

Former Member
0 Likes
598

Hi,

I hope there is no FM for this purpose.

Use the following piece of code in subroutine.

Do.
if FROMDATE > TODATE.
EXIT.
endif.

Append FROMDATE to LT_DATES.
FROMDATE = FROMDATE + 1.
ENDDO.

Regards

Bhupal Reddy