Determine first workday using factory calendar

SAP has a range of (released) calendar functions to be found in function group 'SCAL'. Here's how to use them.

SAP has a range of (released) calendar functions to be found in function group 'SCAL'. With function module 'date_convert_to_factorydate'

it is possible to enter a date and check if this is a workday according to the factory calendar. Furthermore, if the date is not a working day, it returns the first working day before or after the entered date. The code was written in 4.0B but should work for all versions until now.


* Subroutine to check if date is workingday
FORM CHANGE_DATE_INTO_WORKDAY USING    P_LO_DATUM LIKE SY-DATUM
                              CHANGING P_DATUM_O  LIKE SY-DATUM.
DATA:
LO_DATE_IN  LIKE  SCAL-DATE,
LO_DATE_OUT  LIKE  SCAL-DATE,
LO_IND  LIKE  SCAL-INDICATOR.

LO_DATE_IN = P_LO_DATUM.

  CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
       EXPORTING
            CORRECT_OPTION               = '-'
            DATE                         = LO_DATE_IN
            FACTORY_CALENDAR_ID          = 'ZA'
       IMPORTING
            DATE                         = LO_DATE_OUT
*           factorydate                  = lo_facdate
            WORKINGDAY_INDICATOR         = LO_IND
       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.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
P_DATUM_O   = LO_DATE_OUT.

ENDFORM.                    " CHANGE_DATE_INTO_WORKDAY

This was first published in March 2003

Dig deeper on SAP training and certification strategy

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close