Explanation of how to create Customer Exit code that can be used for restricting a characteristic with some values containing a certain pattern
In BW Queries very often there is a requirement to restrict a characteristic with some values to get the correct result. Let us say we have a requirement where we need to restrict the query to only those Departments for which the Department ID starts with D1 or D2. This will be very simple task when there are a limited number of Departments IDs starting with D1 or D2, but what if there are many Departments whose ID starts with D1 or D2 for example.
This can be achieved using a Customer Exit Variable. Following are the steps you need to perform to restrict the characteristic with values having certain pattern.
1: Create a New Variable (say ZVAR_DEPT) on the Characteristic Department with following properties.
Type of Variable: Characteristic Value.
Process By: Customer Exit.
Variable Represents: Multiple Single Values.
Variable Entry is: Mandatory, Non-Input and cannot be changed in Query Navigation
2: Restrict the Characteristic with the variable ZVAR_DEPT.
3: Go to Transaction SE37 and enter "EXIT_SAPLRRS0_001". In the next screen double click on "ZXRSRU01", this will take you to the screen where you can define Customer exit code for Global Variables in Reporting.
4: Include the following code in the Customer Exit code.
IF I_STEP = 1.
DATA: ITAB1 TYPE STANDARD TABLE OF /BI0/SDEPT_ID WITH HEADER LINE.
SELECT * FROM /BI0/SDEPT_ID INTO TABLE ITAB1 WHERE DEPT_ID LIKE 'D1%' OR DEPT_ID LIKE 'D2%'.
L_S_RANGE-SIGN = 'I'.
L_S_RANGE-OPT = 'EQ'.
LOOP AT ITAB1.
L_S_RANGE-LOW = ITAB1-DEPT_ID.
APPEND L_S_RANGE TO E_T_RANGE.