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: 

Getting dates between given date range

Former Member
0 Kudos
10,067

Hi All,

For a given date range in the selection screen i need to find all the dates in between that range into one internal table.

Eg: if i give the date as 21.09.2009 to 20.10.2009 then for this date range in need to get all the dates in between that date range

in one internal table.

Is there any fundtion module to fullfill such a requirement. Please do the needful help.

Thanks

Shashikanth Naram

1 ACCEPTED SOLUTION

Former Member
3,302

why do you need all dates. if you need some kind of range you can use between abc and def. or you can create a range table as well.

any ways for your purpose.

DATA: dt1 type sy-datum VALUE '20090910'.
DATA: dt2 type sy-datum VALUE '20090918'.
DATA : i1 type i.
i1 = dt2 - dt1.
data : it1 type TABLE OF sy-datum WITH HEADER LINE.
do i1 TIMES.
  it1 = dt2.
  dt2 = dt2 - 1.
  APPEND it1.
enddo.

LOOP AT it1.
  WRITE 😕 it1.
ENDLOOP.

10 REPLIES 10

Former Member
0 Kudos
3,302

v_first_date = '21.09.2009' .

wa_date = v_first_date.

append wa_date to t_date.

while date <= '30.10.2009'

wa_date = wa_date + 1

append wa_date to t_date.

endwhile.

This should work. Good luck.

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Kudos
3,302

Hello Pranu,

This should work. Good luck.

You should wish him luck 'coz the code will lead him in to the trap of "infinite loop".


v_first_date = '21.09.2009' .
wa_date = v_first_date.
append wa_date to t_date.

" while date <= '30.10.2009'
while wa_date <= '30.10.2009'.
wa_date = wa_date + 1
append wa_date to t_date.
endwhile.

Cheers,

Suhas

0 Kudos
3,302

Fortunately Typos will be caught in Syntax check so no infinite loop.

0 Kudos
3,302

Hi Suhas,

I there any solution of finding this i.e is any standard funditon module to find this...

Thanks

Shashi

0 Kudos
3,302

Hi

No, I don't think there's a fm to obtain it, u need to use a solution developed by yourself

Max

Former Member
3,303

why do you need all dates. if you need some kind of range you can use between abc and def. or you can create a range table as well.

any ways for your purpose.

DATA: dt1 type sy-datum VALUE '20090910'.
DATA: dt2 type sy-datum VALUE '20090918'.
DATA : i1 type i.
i1 = dt2 - dt1.
data : it1 type TABLE OF sy-datum WITH HEADER LINE.
do i1 TIMES.
  it1 = dt2.
  dt2 = dt2 - 1.
  APPEND it1.
enddo.

LOOP AT it1.
  WRITE 😕 it1.
ENDLOOP.

Former Member
3,302

Hi Sashi,

Just have a look at this link below.

https://wiki.sdn.sap.com/wiki/display/ABAP/FunctionModulerelatedonDate+calculations

It gives the list of all the date related FM's. Maybe something can be of help to your requirement.

Thanks,

Harini

0 Kudos
3,302

Hi passerby,

Here is the correct link.

Regards,
Nemanja

Former Member
0 Kudos
3,302

USE THE FUNCTION MODULE

DAY_ATTRIBUTES_GET

IF IT DOESNT WORK USE

'HR_99S_INTERVAL_BETWEEN_DATES Difference ' AND INCREMENT MONTS AND YEARS

DEFINETLY YOU WILL GET OUTPUT

viva_kd
Participant
0 Kudos
2,722

Dear all, thanks for this query ,thanks my efforts got reduced. this FM DAY_ATTRIBUTES_GET
it resolved my purpose and does exact same, as asked in query, just give start and end date, it will give List of ALL dates between given input 2 dates .. very gratefull.