How to write BW Customer exit to enhance BEx variables

Here I will site an example of how to enhance a BEx variable using BW customer exit.

More details and insightful examples can be accessed in my ebook BEx variable enhancement by Customer Exit.

Display only two years of data in the BEx query

Scenario: Displaying only two years data in the BEx query based on the system date. The BEx query is based on a cube having 5 years of data.

Method:

Create a variable for calday or any time characteristic present in the cube.

I am taking 0calday as an example. SAP provides standard variables also to serve the same purpose. Here I will create a customer exit variable to illustrate the method.

Let the variable name is VAR2

This variable should be Interval value and mandatory.

There is no user input required when the query is accessed. Hence the BEx variable should not be “Ready for Input”.

Based on the system date, an Interval of two years will be calculated. For example, if system date is 24th Feb, 2017, the BEx query should display 2016 and 2017 data.

Drag and drop this variable in the filter section of the query.

Save the query.

Now go to the CMOD transaction and select your project. The project is generally provided by the client and should not be created by the developer. Click Display.

Click on the “components” button and then double click on the Function exit EXIT_SAPLRRS0_001

Double click on Include file name to go into the coding area.

Write the following code:

*Get Current Year and Previous year data in BEx Report
 zcalday type sy-datum.

zyear(4type c.
 WHEN 'VAR2'.
 IF i_step 1.
 zcalday = sy-datum.
 zyear = sy-datum+0(4).
 l_s_range-low = zyear 1.
 l_s_range-high = zyear.
 l_s_range-opt 'EQ'.
 l_s_range-sign 'I'.
 APPEND l_s_range TO e_t_range.
 ENDIF.

 

Save and activate your program.

In this code, zyear will have the current year value. VAR2 variable will have a range of current year-1 to current year.

When the query is executed, it displays the data only for current year and current year-1.

Read my kindle ebook to get more complex and varied examples on customer exit variables and uses.