Calculating number of working days between two dates(e.g.YTD- From 1st January to Current Day) and using it for calculations in queries is a very general case for reporting models.
This blog gives a solution for these type of calculations using factory calendars maintained in BW. To see the available factory calendars TFACD (Factory Calendar definitions) can be used Details of Factory Calendars can be found in TFACS.
There are several function modules using these factory calendars and helping for necessary calculations.(*) One of them is DATE_CONVERT_TO_FACTORYDATE. This function module returns the factory date for the date and factory calendar passed. Double use of this FM (one with start date and one with the end date) will give two numbers and the difference gives the total number of working days between. By using this FM number of working days between two dates can be easily determined.Once you have this function module, it becomes very easy to include this calculation in query level by creating a formula variable(customer exit) and using DATE_CONVERT_TO_FACTORYDATE with the desired time period dates.
As an example; the steps below describes the “number of worked days in a month till today” calculation using this strategy.
– Create a formula in query designer and double-click on it.
– Right Click on Formula Variables Folder in Available Operands Panel
– Create a formula variable “ZWRKDDYS”.
– Select “Customer Exit” for “Processing By” property.
– Go to Transaction CMOD and open project RSR0001
– Insert the following code to the project.
– Save and Activate.
– In the formula the number of working days till today can be seen and used for other calculated key figures.
There is only one factory calendar with id = ‘00’.
Today is not included in calculation.
Project “RSR0001” is already activated in CMOD.
* For all available function modules please check the link.