SAP‎ > ‎Tips‎ > ‎

Working days

*&---------------------------------------------------------------------*
*& Report  ZWORKINGDAYS
*&---------------------------------------------------------------------*

REPORT  zworkingdays.

DATA: date_begin         TYPE sy-datum,
      date_end           TYPE sy-datum,
      current_date       TYPE sy-datum,
      working_indicator  TYPE scal-indicator,
      workdays           TYPE i,
      factory_calendar   TYPE scal-fcalid.
PARAMETERS : p_from TYPE sy-datum.
PARAMETERS : p_to   TYPE sy-datum.
PARAMETERS : p_fac  TYPE scal-fcalid.
date_begin       = p_from.
date_end         = p_to.
factory_calendar = p_fac.

current_date = date_begin.
DO.
  IF current_date > date_end.
    EXIT.
  ENDIF.
  CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
    EXPORTING
      date                         = current_date
      factory_calendar_id          = factory_calendar
    IMPORTING
      workingday_indicator         = working_indicator
    EXCEPTIONS
      calendar_buffer_not_loadable = 1
      correct_option_invalid       = 2
      date_after_range             = 3
      date_before_range            = 4
      date_invalid                 = 5
      factory_calendar_not_found   = 6
      OTHERS                       = 7.
  IF sy-subrc <> 0.
    workdays = 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ENDIF.
  IF working_indicator IS INITIAL.
    ADD 1 TO workdays.
  ENDIF.
  ADD 1 TO current_date.
ENDDO.
WRITE : workdays.

Comments