2006 Jun 07 10:36 AM
Hi,
What is the easiest/simplest way to check date overlapping?
I have date_start1, date_end1, date_start2 and date_end2, and I'd like to know if they're overlapping or not.
I searched for FM OVERLAP, but so far couldn't find one, which would help.
I've found FM TB_TIME_INTERVAL_OVERLAP, which looked promising, however I couldn't make it work, maybe I used a wrong calculation method /I tried several/.
Any idea?
Thanks in advance,
Peter
2006 Jun 07 10:59 AM
hii Peter ,
chk this it works
field-symbols:
<prime> type xyz,
<duplicate> type xyz.
loop at s_date1 assigning <prime>.
loop at s_date2 assigning <duplicate>
where field = <prime>-field .
if <duplicate>-from between <prime>-from
and <prime>-to
or <duplicate>-to between <prime>-from and <prime>-to.
write:/ 'Yes it overlaps'........"
endif.
endloop.
endloop.
you can as well check this func modules .
<b>HR_SGPBS_ADD_TIME_TO_DATE
AFW_TST_DATE_TIME_SEL_GET
IDOC_DATE_TIME_GET
BP_STDT_EDITOR_AT_DATE_TIME
BWFIT_UPDATE_TIMESTAMPS
BWOMT_UPDATE_TIMESTAMPS
C14B_DATE_TIME_COMPARE
C14Z_CALC_DATE_TIME
C14Z_SET_DATE_TIME_LOW_BOUND
CACS_TIMEDATE
CACS_DATE_GET_TIMESTAMP
CACS_TIMESTAMP_GET_DATE</b>
Reward points if helpful
Regards
Naresh
2006 Jun 07 10:39 AM
IF DATE_END1 > DATE_START2.
WRITE:/ "THERE IS OVERLAP".
ENDIF.
rEGARDS,
rAVI
2006 Jun 07 11:10 AM
Hi rAVI,
Thanks!
It seems too easy, but let me check and play around to verify that it covers all the cases.
Peter
2006 Jun 07 10:42 AM
if date_start2 > date_end1.
write:/ 'there is no overlap'
else.
write:/ 'there is an overlap'.
endif.
2006 Jun 07 10:45 AM
Hi,
you can determine difference between your dates so:
DATA: date1 TYPE d,
time1 TYPE t,
date2 TYPE d,
time2 TYPE t,
date_dif(5) TYPE p,
time_dif(5) TYPE p.
date1 = '20030501'.
date2 = '20030630'.
time1 = sy-uzeit.
time2 = sy-uzeit.
CALL FUNCTION 'SD_DATETIME_DIFFERENCE'
EXPORTING
date1 = date1
time1 = time1
date2 = date2
time2 = time2
IMPORTING
datediff = date_dif
timediff = time_dif
EXCEPTIONS
invalid_datetime = 1
OTHERS = 2.
WRITE:/10 date_dif,
/10 time_dif.
2006 Jun 07 10:59 AM
hii Peter ,
chk this it works
field-symbols:
<prime> type xyz,
<duplicate> type xyz.
loop at s_date1 assigning <prime>.
loop at s_date2 assigning <duplicate>
where field = <prime>-field .
if <duplicate>-from between <prime>-from
and <prime>-to
or <duplicate>-to between <prime>-from and <prime>-to.
write:/ 'Yes it overlaps'........"
endif.
endloop.
endloop.
you can as well check this func modules .
<b>HR_SGPBS_ADD_TIME_TO_DATE
AFW_TST_DATE_TIME_SEL_GET
IDOC_DATE_TIME_GET
BP_STDT_EDITOR_AT_DATE_TIME
BWFIT_UPDATE_TIMESTAMPS
BWOMT_UPDATE_TIMESTAMPS
C14B_DATE_TIME_COMPARE
C14Z_CALC_DATE_TIME
C14Z_SET_DATE_TIME_LOW_BOUND
CACS_TIMEDATE
CACS_DATE_GET_TIMESTAMP
CACS_TIMESTAMP_GET_DATE</b>
Reward points if helpful
Regards
Naresh
2006 Jun 07 11:08 AM
If date_start2 <= date_end1.
Endif.
You can also set this check through configration.
Regards,
Wasim Ahmed
2006 Jun 07 1:48 PM
I assume you've already checked that end1 > start1
and end2 > start2.
You need to check if either start2 or end2 fall between start1 and end1
So:
IF ( start2 >= start1 AND start2 <= end1 )
OR ( end2 >= start1 AND end2 <= end1 ).
overlap
ENDIF.
2006 Jun 08 1:21 PM
Thanks a lot for everyone, who helped me!!!!!!
I found with ranges and IN logical condition the solution is more readable and it works fine:
PARAMETERS:
p_start1 TYPE sy-datum,
p_end1 TYPE sy-datum,
p_start2 TYPE sy-datum,
p_end2 TYPE sy-datum.
RANGES:
r_period1 FOR p_start1,
r_period2 FOR p_start2.
r_period1-SIGN = 'I'.
r_period1-option = 'BT'.
r_period1-low = p_start1.
r_period1-high = p_end1.
APPEND r_period1.
r_period2-SIGN = 'I'.
r_period2-option = 'BT'.
r_period2-low = p_start2.
r_period2-high = p_end2.
APPEND r_period2.
IF p_start2 IN r_period1 OR p_end2 IN r_period1 OR
p_start1 IN r_period2 OR p_end1 IN r_period2.
WRITE:/ 'THERE IS OVERLAP'.
ELSE.
WRITE:/ 'NO OVERLAP'.
ENDIF.
2007 Jul 12 1:14 PM
Hi All,
You can use the FM to validate the date overlap when from date and to date in which the date ranges have been given.
<i> CALL FUNCTION <b>'GM_VALIDATE_DATE_RANGE'</b>
EXPORTING
i_from_date = sy-datum
i_to_date = c_enddt "'99991231'
TABLES
t_daterange = p_dates
EXCEPTIONS
ranges_overlap = 1
range_has_holes = 2
continuous_but_excessive = 3
OTHERS = 4
erro_message = 99.
CASE sy-subrc.
WHEN '0'.
WHEN '1'.
MESSAGE e004(z_common) DISPLAY LIKE 'E'
WITH 'Date range should not overlap with Existing One'(003).
WHEN '2'.
MESSAGE e004(z_common) DISPLAY LIKE 'E'
WITH 'Date range should not overlap with Existing One'(003).
ENDCASE.</i>
<b>OR</b>
Only for date ranges validation no matter whatever the date ranges are given.
you can use the Z function module from the above one mentioned.
*****************************************************************************************
*****************************************************************************************
<b><i>FUNCTION zgm_validate_date_range.
*"----
""Local Interface:
*" IMPORTING
*" REFERENCE(I_FROM_DATE) TYPE DATS OPTIONAL
*" REFERENCE(I_TO_DATE) TYPE DATS OPTIONAL
*" TABLES
*" T_DATERANGE STRUCTURE GMDATERANGE
*" EXCEPTIONS
*" RANGES_OVERLAP
*" RANGE_HAS_HOLES
*" CONTINUOUS_BUT_EXCESSIVE
*"----
DATA: i TYPE i,
l_next_date LIKE sy-datum,
l_first_date LIKE sy-datum,
l_last_date LIKE sy-datum,
no_days TYPE tfmatage,
cnt_next TYPE i,
w_daterange TYPE gmdaterange.
DESCRIBE TABLE t_daterange LINES i.
IF i > 1.
SORT t_daterange BY from_date.
First determine if the slices are continuous and have
no gaps.
LOOP AT t_daterange.
cnt_next = sy-tabix + 1.
IF sy-tabix > 1. " not first record
IF t_daterange-from_date <= l_next_date.
RAISE ranges_overlap.
ENDIF.
IF t_daterange-to_date <= l_next_date.
RAISE range_has_holes.
ENDIF.
ELSE.
save first date
MOVE t_daterange-from_date TO l_first_date.
ENDIF.
update end of range
MOVE t_daterange-to_date TO : l_last_date,
l_next_date.
ENDLOOP.
ENDIF.
ENDFUNCTION.</i></b>
*****************************************************************************************
*****************************************************************************************
Thanks
Ramesh Babu N