Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

TIME OVERLAPPING.....

Hi,

I am having DATE1-TIME1 & DATE2-TIME2 and DATE3-TIME3 & DATE4-TIME4.

How to calculate whether DATE1-TIME1 & DATE2-TIME2 and DATE3-TIME3 & DATE4-TIME4 overlap.

Please help.

Thanks in advance....

Tags:
replied

Hello Sandeep

The previous proposal by Aparna is obviously wrong:

--------------------> date/time scale
3-----------4
                      1-----------2

Date 2 > Date 3 yet the intervals do not overlap.

Sample report ZUS_SDN_DATE_RANGE_CHECK shows how to solve such problem:

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_DATE_RANGE_CHECK
*&
*&---------------------------------------------------------------------*
*& Thread: TIME OVERLAPPING.....
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1067045"></a>
*&---------------------------------------------------------------------*

REPORT  zus_sdn_date_range_check.

"TZNTSTMPS: UTC Time Stamp in Short Form (YYYYMMDDhhmmss)
DATA: gd_tstamp1   TYPE tzntstmps,
      gd_tstamp2   TYPE tzntstmps,
      gd_tstamp3   TYPE tzntstmps,
      gd_tstamp4   TYPE tzntstmps.

PARAMETER:
  p_day1  TYPE d  DEFAULT '20080101',
  p_tim1  TYPE t  DEFAULT '100000'.

PARAMETER:
  p_day2  TYPE d  DEFAULT '20080110',
  p_tim2  TYPE t  DEFAULT '110000'.

PARAMETER:
  p_day3  TYPE d  DEFAULT '20080105',
  p_tim3  TYPE t  DEFAULT '120000'.

PARAMETER:
  p_day4  TYPE d  DEFAULT '20080111',
  p_tim4  TYPE t  DEFAULT '130000'.


START-OF-SELECTION.

  CALL FUNCTION 'CONVERT_INTO_TIMESTAMP'
    EXPORTING
      i_datlo           = p_day1
      i_timlo           = p_tim1
*     I_TZONE           = SY-ZONLO
    IMPORTING
      e_timestamp       = gd_tstamp1.

  CALL FUNCTION 'CONVERT_INTO_TIMESTAMP'
    EXPORTING
      i_datlo           = p_day2
      i_timlo           = p_tim2
*     I_TZONE           = SY-ZONLO
    IMPORTING
      e_timestamp       = gd_tstamp2.

  CALL FUNCTION 'CONVERT_INTO_TIMESTAMP'
    EXPORTING
      i_datlo           = p_day3
      i_timlo           = p_tim3
*     I_TZONE           = SY-ZONLO
    IMPORTING
      e_timestamp       = gd_tstamp3.

  CALL FUNCTION 'CONVERT_INTO_TIMESTAMP'
    EXPORTING
      i_datlo           = p_day4
      i_timlo           = p_tim4
*     I_TZONE           = SY-ZONLO
    IMPORTING
      e_timestamp       = gd_tstamp4.


  IF ( gd_tstamp3 BETWEEN gd_tstamp1 AND gd_tstamp2 )  OR
     ( gd_tstamp4 BETWEEN gd_tstamp1 AND gd_tstamp2 ).
    MESSAGE 'Date ranges do overlap' TYPE 'S'.
  ELSE.
    MESSAGE 'No overlag of date ranges' TYPE 'S'.
  ENDIF.

END-OF-SELECTION.

Regards

Uwe

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question