Tip

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

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

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.