Child pages
  • Customer Exit Variables in SAP BI
Skip to end of metadata
Go to start of metadata

Steps:

First we are going to create the variables in the Query Designer:

1.Create User Entry Variable on Calendar Day (0CALDAY). We will use this variable in the selection screen of the report and in order to save users effort this variable will be always filled with current date from user exit of course it can be always changed from the user.

Create ZENTRYDATE variable on 0CALDAY

In General Tab:

Type of Variable = Characteristic Value

Processing by = Customer Exit

Reference Characteristic = Calendar Day

In Details Tab:

Variable Represents = Single value

Variable is = Mandatory

Check, Variable is Ready for Input

Here are the screenshots with the required settings:

 

2.Drag and Drop a keyfigure and the restrict with the above created variable to make it available in the selection screen. (Use the screenshots below for reference)

Note that we will use this keyfigure just for input and we don’t need to see it in the report.

3.Create 2 variables of type customer exit with below mentioned properties on Calendar Day (0CALDAY)

Create ZYD (CURRENT YTD VARAIBLE) and ZPREVYTD (PREVIOUS YTD VARAIBLE)

In General Tab:

Type of Variable = Characteristic Value

Processing by = Customer Exit

Reference Characteristic = Calendar Day

In Details Tab:

Variable Represents = Interval

Variable is = Optional

Here are the screenshots with the required settings:

4. Drag and Drop a key figure and the restrict with the above created variables so it can show up in the report with the volume for the selected period in our case YTD volume and previous year YTD volume. (Use the screenshot below for reference)

5. Create two Calculated Key Figures with formula variables. Note that we have to create two calculated key figures and we should use two different formula variables in them one to calculate current YTD working days based on the factory calendar and one to calculate previous year working days.(Use the screenshot below for reference)

Variable settings below:

Create ZWDAYS (Current Year Working Days) and ZLY(Previous Year Working Days)

In General Tab:

Type of Variable = Formula

Processing by = Customer Exit

In Details Tab:

Variable Represents = Interval

Variable is = Optional

Here are the screenshots with the required settings:

Now we have to write the code in order to match our business scenario requirments:

Go to transaction CMOD, if there is no existing project create one and include Enhancement RSR00001: BI: Enhancements for Global Variables in Reporting.

Then enter the enhancement:

And Double Click on INCLUDE ZXRSRU01.

Now we are ready to write our code:

First we want to populate the today date in selection screen:

CASE I_VNAM.

WHEN 'ZENTRYDATE'.

DATA l_s_range type rrrangesid.

IF I_STEP = 1.

l_s_range-low = sy-datum.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.


ENDIF.

Now when we start the report we’ll get a today date in the variable ‘ENTRY DATE’. User always can change that date.

Second step is to restrict the Current YTD Volume to include only the YTD Volume based on the ENTRY DATE:

 WHEN 'ZYTD'.

 DATA: loc_var_range type RRRANGEEXIT,
       l_s_range type rrrangesid,
       en_year(4) type c,
       f_day_year(8) type c,
       range_low(8) type c.
 IF I_STEP = 2.

 LOOP AT i_t_var_range INTO loc_var_range WHERE VNAM = 'ZENTRYDATE'.

 clear l_s_range.

 range_low = loc_var_range-low.
 en_year = range_low+0(4).

 CONCATENATE en_year '0101' INTO f_day_year.

 l_s_range-low = f_day_year.
 l_s_range-high = range_low.
 l_s_range-sign = 'I'.
 l_s_range-opt = 'BT'.

 APPEND l_s_range TO e_t_range.

 ENDLOOP.

 ENDIF.


After that we do the same for the Previous YTD Volume:

 WHEN 'ZPREVYTD'.

 DATA: loc_var_range type RRRANGEEXIT,
       l_s_range type rrrangesid,
       en_year(4) type c,
       f_day_year(8) type c,
       en_mmdd(4) type c,
       range_low(8) type c.


 IF I_STEP = 2.

 LOOP AT i_t_var_range INTO loc_var_range WHERE VNAM = 'ZENTRYDATE'.

 clear l_s_range.

 range_low = loc_var_range-low.
 en_year = range_low+0(4).
 en_year = en_year - 1.

 en_mmdd = range_low1+4(4).

 clear range_low.

 CONCATENATE en_year '0101' INTO f_day_year.
 CONCATENATE en_year en_mmdd INTO range_low.

 l_s_range-low = f_day_year.
 l_s_range-high = range_low.
 l_s_range-sign = 'I'.
 l_s_range-opt = 'BT'.

 APPEND l_s_range TO e_t_range.

 ENDLOOP.
 ENDIF.

Next important step is to calculate the working days based on the ENTRY DATE. To do that we use the following Function module DATE_CONVERT_TO_FACTORYDATE. This FM returns as result number of the working days since the beginning of the Factory Calendar this is why we use start date and end date to calculate number of the working days for given period. Note that the result doesn’t include today.

 WHEN 'ZWDAYS'.

 data:   e_t_data type rrrangesid,
         loc_var_range type RRRANGEEXIT,
         start_date type SCAL-FACDATE,
         end_date type SCAL-FACDATE,
         fact_days type SCAL-FACDATE,
         en_year type c,
         f_day_year type d,
         range_low_f type d.

 IF I_STEP = 2.

 LOOP AT i_t_var_range INTO loc_var_range WHERE VNAM = 'ZENTRYDATE'.

 clear e_t_data.

 range_low_f = loc_var_range-low.
 en_year = range_low_f+0(4).

 CONCATENATE en_year '0101' INTO f_day_year.

   CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
     EXPORTING
      CORRECT_OPTION                      = '-'
       DATE                               = range_low_f
       FACTORY_CALENDAR_ID                = '01'
    IMPORTING
      FACTORYDATE                        = end_date.

   CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
     EXPORTING
      CORRECT_OPTION                      = '+'
       DATE                               = f_day_year
       FACTORY_CALENDAR_ID                = '01'
    IMPORTING
      FACTORYDATE                         = start_date.

   fact_days = end_date - start_date.
   e_t_data-sign = 'I'.
   e_t_data-opt = 'EQ'.
   e_t_data-low = fact_days.
   APPEND e_t_data TO e_t_range.

   ENDLOOP.
   ENDIF.

We have to do the same for the previous year:

 WHEN 'ZLY'.

 data:   e_t_data type rrrangesid,
         loc_var_range type RRRANGEEXIT,
         start_date type SCAL-FACDATE,
         end_date type SCAL-FACDATE,
         fact_days type SCAL-FACDATE,
         en_year type c,
         f_day_year type d,
         range_low_fact type d.

 IF I_STEP = 2.

 LOOP AT i_t_var_range INTO loc_var_range WHERE VNAM = 'ZENTRYDATE'.

 clear e_t_data.

 range_low_fact = loc_var_range-low.
 en_year = range_low_fact+0(4).
 en_year = en_year - 1.

 en_mmdd = range_low_fact+4(4).

 clear range_low_fact.

 CONCATENATE en_year '0101' INTO f_day_year.
 CONCATENATE en_year en_mmdd INTO range_low_fact.


   CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
     EXPORTING
      CORRECT_OPTION                      = '-'
       DATE                               = range_low_fact
       FACTORY_CALENDAR_ID                = '01'
    IMPORTING
      FACTORYDATE                        = end_date.

   CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
     EXPORTING
      CORRECT_OPTION                      = '+'
       DATE                               = f_day_year
       FACTORY_CALENDAR_ID                = '01'
    IMPORTING
      FACTORYDATE                         = start_date.

   fact_days = end_date - start_date.
   e_t_data1-sign = 'I'.
   e_t_data1-opt = 'EQ'.
   e_t_data1-low = fact_days.
   APPEND e_t_data1 TO e_t_range.

   ENDLOOP.
   ENDIF.
 ENDCASE.

Now user exit should be saved and activated.

In order to test the Variable and for Debugging we can use transaction RSRT.

And now, how our variable is working:

When we run the query we should get variable window with Entry date today (Use the screenshots below for reference).

After we run the report we can see how our variables are currently working:

In our case we have equal number of working days, please refer to a screen shot with date in the past: