Skip to end of metadata
Go to start of metadata
FUNCTION zweek_difference.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(END_DATE) LIKE  SCAL-DATE
*"     VALUE(START_DATE) LIKE  SCAL-DATE
*"  EXPORTING
*"     REFERENCE(DAY_DIFF) TYPE  I
*"     REFERENCE(WEEK_DIFF) TYPE  I
*"----------------------------------------------------------------------
**Data Declaration
  DATA week1         LIKE scal-week.
  DATA week2         LIKE scal-week.
  DATA date_st       LIKE scal-date.
  DATA day           LIKE scal-indicator.
  DATA date_diff(5)  TYPE n.
  DATA date_change   TYPE sy-datum.
**To get the Week of Start Date
  CALL FUNCTION 'DATE_GET_WEEK'
    EXPORTING
      date = start_date
    IMPORTING
      week = week1.
  IF sy-subrc = 0.
**To get the First Day of the week from Start Date
    CALL FUNCTION 'WEEK_GET_FIRST_DAY'
      EXPORTING
        week = week1
      IMPORTING
        date = date_st.
    IF sy-subrc = 0.
    ENDIF.
  ENDIF.
  date_diff = end_date - date_st.
  day_diff  = date_diff MOD 7.
  week_diff = date_diff DIV 7.
  IF ( ( day_diff >= 1 ) AND ( day_diff < 7 ) ).
    week_diff = week_diff + 1.
  ENDIF.
  date_change = end_date.
  IF day_diff = 0.
    CALL FUNCTION 'DATE_COMPUTE_DAY'
      EXPORTING
        date = date_change
      IMPORTING
        day  = day.
    IF sy-subrc = 0.
      IF day = 1.
        week_diff = week_diff + 1.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFUNCTION.