ABAP log

March 15, 2007

Working with SAP plant (factory) calendars in ABAP.

Filed under: ABAP, SAP — abaplog @ 8:01 pm

Every plant in SAP can have its own calendar that defines plant working days. This calendar is used by planning functions to determine whether a particular day is working one or not. You can see the effects if, for example, you try to create a delivery schedule on Sunday, and the system says that actually the next working day is another one.

Very ofter we have to account for working days and exclude weekends and holidays in our ABAP. To do that, SAP provides two functions modules that are used to convert between the “normal” date and the enumerated “factory day”. The factory day is a number assigned to each working day in plant calendar. The functions are FACTORYDATE_CONVERT_TO_DATE and DATE_CONVERT_TO_FACTORYDATE and they are documented directly in SAP, in SAP standalone help (BC Extended Applications Function Library) and, of course, at se37.com.
The typical use of those functions is to add a number of days to a given date, skipping holidays and weekends. This is often asked on SAP-related forums and is one of the subjects in SAPfans ABAP FAQ.

I use those functions also for simple checks whether a day is working or not, and to move a date to a working day (forwards or backwards). Below are forms that I use. The factory calendar (FABKL) can be read directly from the table T001W. The parameter pf_correct should be ‘+’ to move forward or ‘-‘ to move backwards.

form move_to_working
    pf_fabkl   type fabkl
    pf_correct type cind
    pf_date    type datum.

    lf_newdate type datum.

  check not pf_fabkl is initial.
            correct_option               = pf_correct
            date                         = pf_date
            factory_calendar_id          = pf_fabkl
            date                         = lf_newdate
            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.
    pf_date = lf_newdate.


form is_working_day
    pi_werks like pbim-werks
    pi_date  like sy-datum
    pi_fabkl   type fabkl
    po_working like space.

    w_work  like SCAL-INDICATOR,
    w_fabkl like t001w-fabkl.

  clear po_working.
            date                         = pi_date
            factory_calendar_id          = pi_fabkl
            workingday_indicator         = w_work
            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 and w_work is initial.
    po_working = c_x.



  1. Hey,

    just wanted to say hi, tell you I appreciate what you are doing on your blog. It’s always a nice read even though I try not to do ABAP anymore and have switched to the bright (Java) site of life;) But it’s good to see someone using this blogging stuff to post more technical notes. You’re probably on SDN also, right? Have a blog there too? Hope so, if not you should! Keep up the good work.

    Btw. this factory calendar in SAP is a really neat stuff. Have used it a lot in SD and PP. Helps you a lot but someone has to maintain it.


    Comment by Oliver — March 16, 2007 @ 5:39 am

  2. Thanks! I’m not on SDN – I prefer to be free, i.e. sapfans.com and my own web log.

    Regarding factory calendars: SAP comes with all possible calendars in standard, you have to maintain your own only if you do something really special.

    Comment by abaplog — March 17, 2007 @ 8:17 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: