Determine first workday using factory calendar

Determine first workday using factory calendar

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.

    Requires Free Membership to View

    When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSAP.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSAP.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

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

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.