Applies to

SAP BW 7.x system, for more information, visit the Business Intelligence homepage,

https://help.sap.com/saphelp_nw73ehp1/helpdata/en/b2/e50138fede083de10000009b38f8cf/frameset.htm

Summary

This Document describes how to handle date calculations using the factory calendar.

Author Bio

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.

Details

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.

P_1.png

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. 1. First create a function group in SE80 or you may use the existing function group.

  1. 2. Now create a structure ZBW_RKE_DAT as given below in SE11. This structure is returned as an internal table by the FM.

       P_2.png

  1. 3. Inside your FG, Right click on the function module and create the function module with name ZBW_RKE_SELECT_FACTDAYS_FOR_PE

P_3.png

  1. 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!!

FUNCTION RKE_SELECT_FACTDAYS_FOR_PERIOD.
*”———————————————————————-
*”*”Lokale Schnittstelle:
*”       IMPORTING
*”             VALUE(I_DATAB) LIKE  KONA-DATAB
*”             VALUE(I_DATBI) LIKE  KONA-DATBI
*”             VALUE(I_FACTID) LIKE  TKEVS-FCALID
*”       TABLES
*”              ETH_DATS STRUCTURE  RKE_DAT
*”       EXCEPTIONS
*”              DATE_CONVERSION_ERROR
*”———————————————————————-

DATA: L_V_AKTDAT LIKE SCALDATE.

DATA: L_V_INDICATOR LIKE SCALINDICATOR.
************************************************************************

CLEAR  : ETH_DATS.
REFRESH: 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’
EXPORTING
DATE                         = L_V_AKTDAT
FACTORY_CALENDAR_ID         
= I_FACTID  
IMPORTING
WORKINGDAY_INDICATOR        
= L_V_INDICATOR
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 SYSUBRC NE 0.
MESSAGE ID SYMSGID TYPE SYMSGTY NUMBER SYMSGNO
WITH SYMSGV1 SYMSGV2 SYMSGV3 SYMSGV4
RAISING DATE_CONVERSION_ERROR.
ENDIF.

* 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.
CLEAR ETH_DATS.
ETH_DATS
PERIODAT = L_V_AKTDAT.
APPEND ETH_DATS.
ENDIF.

L_V_AKTDAT = L_V_AKTDAT + 1.

ENDWHILE.

ENDFUNCTION.

Now let us test the FM,


P_4.png

P_5.png

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. 

     

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Lakshminarasimhan N Post author

    Hi, In my code i have declared a internal table LT_ZBW_RKE_DAT to receive the data returned by the Function module( ETH_DATS ). The    DESCRIBE TABLE LT_ZBW_RKE_DAT LINES AGE after the FM when declared gives the total number of lines in the internal table LT_ZBW_RKE_DAT, which is equivalent to the total number of days between the start date and the end date. Hope this is clear. Revert back for any queries.

    (0) 

Leave a Reply