Ref: SDN Wiki
Author: Ramakrishna Gattikoppula

Scenario
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 limited number of Departments IDs starting with D1 or D2, but what if there are many Departments whose ID starts with D1 or D2.

Solution
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.

Step1: Create a New Variable(say ZVAR_DEPT) on the Characteristic Department with following properties.

Type of Variable: Characteristic Value.
Processing By: Customer Exit.
Variable Represents: Multiple Single Values.
Variable Entry is: Mandatory, Not Ready for Input and Cannot be changed in Query Navigation

Step 2: Restrict the Characteristic with the variable ZVAR_DEPT.

Step 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.

Step 4: Include the following code in the Customer Exit code.

WHEN 'ZVAR_DEPT'.
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%'.
CLEAR: L_S_RANGE.
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.
ENDLOOP.
CLEAR L_S_RANGE.
ENDIF.