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