Factory calendar calculation in SAP BW system
SAP BW 7.x system, for more information, visit the Business Intelligence homepage,
This Document describes how to handle date calculations using the factory calendar.
Lakshminarasimhan Narasimhamurthy is BW certified and ABAP certified consultant and worked on multiple implementation, development and support project’s within India and outside of India. He has worked for fortune 500 clients like Nestle, Warner Bros, GCC, General Electric etc. He is strong in BW, BW related ABAP, HANA modeling, BW-HANA modeling, BODS and BO/BI tools like WEBI, Design Studio, IDT and Lumira.
Usually the factory calendar is maintained in the source system (ECC/CRM).We replicate the calendar via “Transfer global settings” to SAP BW system at frequent intervals.
The factory calendar is visible via the t-code SCAL.
Now we can create factory calendars even in BW system for the process chain purpose or any other purposes.
Now we have a Business requirement to exclude the weekends in my employee performance report.
Every task (workitem) gets assigned to an employee via workflow. After few days the employee completes the task. Now business wants to know the number of days taken by the employee to close the task excluding the weekends, Public holidays. This calculation i am doing at the end routine.
In ECC/CRM system we have a function module to “RKE_SELECT_FACTDAYS_FOR_PERIOD” to calculate the number of days excluding the weekends. Unfortunately we don’t have this function module in the sap bw system.
Now let me know show on how to create the same FM in BW system,
- 1. First create a function group in SE80 or you may use the existing function group.
- 2. Now create a structure ZBW_RKE_DAT as given below in SE11. This structure is returned as an internal table by the FM.
- 3. Inside your FG, Right click on the function module and create the function module with name ZBW_RKE_SELECT_FACTDAYS_FOR_PE
- 4. Now it turns out to be very simple, just copy all import parameters, tables from the original FM to your ZBW_RKE_SELECT_FACTDAYS_FOR_PE FM. Also do copy the source code and then FM is ready for use!!
*” VALUE(I_DATAB) LIKE KONA-DATAB
*” VALUE(I_DATBI) LIKE KONA-DATBI
*” VALUE(I_FACTID) LIKE TKEVS-FCALID
*” ETH_DATS STRUCTURE RKE_DAT
DATA: L_V_AKTDAT LIKE SCAL–DATE.
DATA: L_V_INDICATOR LIKE SCAL–INDICATOR.
CLEAR : ETH_DATS.
L_V_AKTDAT = I_DATAB.
* do it for all days in space of time
WHILE L_V_AKTDAT <= I_DATBI.
CALL FUNCTION ‘DATE_CONVERT_TO_FACTORYDATE’
DATE = L_V_AKTDAT
FACTORY_CALENDAR_ID = I_FACTID
WORKINGDAY_INDICATOR = L_V_INDICATOR
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 NE 0.
MESSAGE ID SY–MSGID TYPE SY–MSGTY NUMBER SY–MSGNO
WITH SY–MSGV1 SY–MSGV2 SY–MSGV3 SY–MSGV4
* indicator is space if actual day is a working day
* if indicator is not space the actual day isn’t a working day
IF L_V_INDICATOR EQ SPACE.
ETH_DATS–PERIODAT = L_V_AKTDAT.
L_V_AKTDAT = L_V_AKTDAT + 1.
Now let us test the FM,
The days between 01.Aug.2016 till 08.Aug.2016 belonging to factory calendar “AE”(United Arab emirates) is
6 days. The function module by default include the “from date” and “to date” specified in calculation.
Note – Friday & Saturday are the weekly holidays in UAE.
Add one more line in the code.
DESCRIBE TABLE LT_ZBW_RKE_DAT LINES AGE.
AGE is declared as an integer. The lines of the internal table is counted and stored in the AGE variable.