Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

S19 - BW Query & Exit variables

BW Query 1. BW Query in Eclipse 4th Oct: 8:30 AM - 10:30 AM


2. BW Query based on Calculation view with input
parameters
3. BW Query new way of Customer Exit and HANA Exit
variables
4. Debugging the customer and hana exit variables

Batch_2 Page 1
Pre session Q & A

Shakthi Difference between X and P cold store process in Composite provider


What does materialize intermediate query result mean

Batch_2 Page 2
BW Query

Definition A query is the formal definition of a multidimensional query. You use analytic queries to analyze the data in the
SAP BW∕4HANA.

It's created in Eclipse and is called BW Analytic Query.


Condition

Exception

Batch_2 Page 3
BW Query Enhancement - Requirement

Sales Item Customer Exit (ABAP Layer, Can accept multiple values or ranges for a variable)
1. Take manual input from user for Fiscal period in a manual input variable.
This manual input variable must be auto populated with current fiscal period.
2. Get the fiscal period from the manual fiscal period variable and create a range (calculation)
Take the year and get the 1st period of the year (similar to YTD requirements) - This is the from value of the
interval.
Take the fiscal period entered in the manual fiscal period variable and treat this as To value of the interval.
Sales Header HANA Exit (AMDP based. HANA Layer and can only accept single value for a variable)
1. Get the calendar day input from user in a manual input variable.
This variable must be auto populated by current day -1.
2. Take the manual input calday and create a range:
From: Start of the year.
To: till the manual input calday

Batch_2 Page 4
BW Query Enhancement - BADI

Old Vs New way Old Way:

• The only available extension RSR00001 (Customer Exit Global Variables in Reporting).
• Transaction SMOD.
• Function module EXIT_SAPLRRS0_001 gets called at execution time of a report)
The function block EXIT_SAPLRRS0_001 calls the include ZXRSRU01 which is in the
customer namespace to perform customization.
-----------------------------------------------------------------------------------------------------------------------------------
New Way:

• Via
Enhancement Spot: RSROA_VARIABLES_EXIT
BADI name: RSROA_VARIABLES_EXIT_BADI

• Available since BW 7.3.


• The BAdI is a filter-based BAdI.
So, you can define e.g. only one certain InfoObject for which this BAdI should be called.

BW4HANA BW/4HANA does not support the old implementation any longer which is based on SMOD.
Now, it's a prerequisite to create the enhancement implementation for the enhancement spot
RSROA_VARIABLES_EXIT_BADI if you want to work with customer exit variables

Migration Mandatory? • Migration is not needed.


• The BADI Framework calls customer exit function module if there's one:

Process 1. Create a Customer Exit variable for the required Infoobject:

2. Create another manual input single value variable for 0FISCPER. This will be used to
capture input fisper from user:

Batch_2 Page 5
3. Now add these 2 in the filter in the BW Query:

4. Access the Enhancement Spot - RSROA_VARIABLES_EXIT (Tcode Se18).


Enhancement Spot = Group of all the related enhancement elements (e.g. Group of related BADI implementations)

5. Display the enhancement spot:

6. On the tab 'Enhancement Spot Element Defnts', click on the 'BADI Implementation':

7. Create 'Enhancement Implementation' first:

Batch_2 Page 6
8. Create an Enhancement Implementation by providing name and text.
The composite Enh Impl can be left blank.

9. Once created, select the created Enh Impl and click ok:

10. It'll ask for BADI implementation and Implementation Class.


Provide the details and activate the new enhancement implementation:
Now, you should have 3 things activated:
1. Enhancement Implementation
2. BADI Implementation
3. Implementing Class

11. Now come out of this and go to tcode SE19 and provide the name of the Enhancement Implementation
and change it:

12. Now create the filter combinations.


Keep first one as 'blank' for i_step = 3.
The other ones you can keep as name of Infoobject on which customer exit variable is created.

Batch_2 Page 7
Note: To extend the above functionality to Formula and Text variables of processing type Customer Exit the IOBJNM filter needs to be populated with the
values ‘1FORMULA‘ and ‘1TEXT‘ respectively in new Filter Combinations.

13. Now double click on 'Implementing Class' and write the code:

Method Signature

Batch_2 Page 8
Method Signature

Other variables

Sample Code

Batch_2 Page 9
Code Blocks

Customer Exit: CLASS zcl_var_badi_impl DEFINITION


Inefficient code PUBLIC
FINAL
CREATE PUBLIC .

PUBLIC SECTION.

INTERFACES if_badi_interface .
INTERFACES if_rsroa_variables_exit_badi .

ENDCLASS.

CLASS zcl_var_badi_impl IMPLEMENTATION.

METHOD if_rsroa_variables_exit_badi~process.

DATA: l_s_range TYPE rsr_s_rangesid,


lv_fiscvar TYPE t009-periv,
lv_fiscper TYPE t009b-poper,
lv_fiscyr TYPE t009b-bdatj.

CASE i_vnam.

WHEN 'ZVAR_CE_I_FISPER'.

lv_fiscvar = 'K4'.

IF i_step = 1. "Before the pop-up

CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'


EXPORTING
i_date = sy-datum
i_periv = lv_fiscvar "Fiscal year Variant - refer to tab T009B
IMPORTING
e_buper = lv_fiscper " Fiscal Period
e_gjahr = lv_fiscyr " Fiscal year
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.

IF sy-subrc = 0.

CLEAR l_s_range.

CONCATENATE lv_fiscyr lv_fiscper into l_s_range-low.


l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.

APPEND l_s_range TO c_t_range.

ENDIF.

ENDIF.

ENDCASE.

ENDMETHOD.

Batch_2 Page 10
ENDMETHOD.

ENDCLASS.

Customer Exit class ZCL_VAR_BADI_IMPL definition


Efficient Code public
final
create public .

public section.

interfaces IF_BADI_INTERFACE .
interfaces IF_RSROA_VARIABLES_EXIT_BADI .

class-methods ZV_IST1_ZV_CE_MI_S_FISCPER_BT2
importing
value(I_VNAM) type RSZGLOBV-VNAM
value(I_VARTYP) type RSZGLOBV-VARTYP
value(I_IOBJNM) type RSZGLOBV-IOBJNM
value(I_S_COB_PRO) type RSD_S_COB_PRO
value(I_S_RKB1D) type RSR_S_RKB1D
value(I_PERIV) type RRO01_S_RKB1F-PERIV
value(I_T_VAR_RANGE) type RRS0_T_VAR_RANGE
value(I_STEP) type I default 0
changing
!C_T_RANGE type RSR_T_RANGESID optional
!C_NO_SCREEN type RS_BOOL optional
!C_CHECK_AGAIN type RS_BOOL optional
!C_S_CUSTOMER type RRO04_S_CUSTOMER optional
raising
CX_RS_ERROR .

**********************************************************************
class-methods ZV_IST2_ZV_CE_I_FISCPER_BT2
importing
value(I_VNAM) type RSZGLOBV-VNAM
value(I_VARTYP) type RSZGLOBV-VARTYP
value(I_IOBJNM) type RSZGLOBV-IOBJNM
value(I_S_COB_PRO) type RSD_S_COB_PRO
value(I_S_RKB1D) type RSR_S_RKB1D
value(I_PERIV) type RRO01_S_RKB1F-PERIV
value(I_T_VAR_RANGE) type RRS0_T_VAR_RANGE
value(I_STEP) type I default 0
changing
!C_T_RANGE type RSR_T_RANGESID optional
!C_NO_SCREEN type RS_BOOL optional
!C_CHECK_AGAIN type RS_BOOL optional
!C_S_CUSTOMER type RRO04_S_CUSTOMER optional
raising
CX_RS_ERROR .

**********************************************************************
class-methods _TEMPLATE
importing
value(I_VNAM) type RSZGLOBV-VNAM
value(I_VARTYP) type RSZGLOBV-VARTYP
value(I_IOBJNM) type RSZGLOBV-IOBJNM
value(I_S_COB_PRO) type RSD_S_COB_PRO
value(I_S_RKB1D) type RSR_S_RKB1D
value(I_PERIV) type RRO01_S_RKB1F-PERIV
value(I_T_VAR_RANGE) type RRS0_T_VAR_RANGE
value(I_STEP) type I default 0
changing
!C_T_RANGE type RSR_T_RANGESID optional

Batch_2 Page 11
!C_T_RANGE type RSR_T_RANGESID optional
!C_NO_SCREEN type RS_BOOL optional
!C_CHECK_AGAIN type RS_BOOL optional
!C_S_CUSTOMER type RRO04_S_CUSTOMER optional
raising
CX_RS_ERROR .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.

CLASS ZCL_VAR_BADI_IMPL IMPLEMENTATION.

METHOD if_rsroa_variables_exit_badi~process.

**********************************************************************
* Main method which calls individual methods for every variable
**********************************************************************

DATA: lv_method TYPE string.


FIELD-SYMBOLS: <lt_data> TYPE rsr_t_rangesid.

ASSIGN c_t_range TO <lt_data>.

CASE i_step.

WHEN 1. "Before the pop-up.


CONCATENATE 'ZV_IST1_' i_vnam INTO lv_method.

WHEN 2. "After the pop-up.


CONCATENATE 'ZV_IST2_' i_vnam INTO lv_method.

* WHEN 3. "Check values of variables.


* "For I_STEP = 3 it’s not specific to a variable or infoobject, therefore we can use a common method.
* lv_method = 'ZVAR_ISTEP3_VALIDITY'.

* WHEN 0. "Authorization check.


* CONCATENATE 'ZV_IST0_' i_vnam INTO lv_method.

ENDCASE.

TRY.
CALL METHOD (lv_method)
EXPORTING
i_vnam = i_vnam
i_vartyp = i_vartyp
i_iobjnm = i_iobjnm
i_s_cob_pro = i_s_cob_pro
i_s_rkb1d = i_s_rkb1d
i_periv = i_periv
i_t_var_range = i_t_var_range
i_step = i_step
CHANGING
c_t_range = <lt_data>
c_no_screen = c_no_screen
c_check_again = c_check_again
c_s_customer = c_s_customer.

CATCH cx_sy_dyn_call_illegal_method.

ENDTRY.

Batch_2 Page 12
ENDMETHOD.

METHOD zv_ist1_zv_ce_mi_s_fiscper_bt2.

**********************************************************************
* Method for variable: zv_ce_mi_s_fiscper_bt2 (i_step = 1)
**********************************************************************

DATA: l_s_range TYPE rsr_s_rangesid,


lv_fiscvar TYPE t009-periv,
lv_fiscper TYPE t009b-poper,
lv_fiscyr TYPE t009b-bdatj.

lv_fiscvar = 'K4'.

IF i_step = 1. "Before the pop-up

CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'


EXPORTING
i_date = sy-datum
i_periv = lv_fiscvar "Fiscal year Variant - refer to tab T009B
IMPORTING
e_buper = lv_fiscper " Fiscal Period
e_gjahr = lv_fiscyr " Fiscal year
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.

IF sy-subrc = 0.

CLEAR l_s_range.

CONCATENATE lv_fiscyr lv_fiscper into l_s_range-low.


l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.

APPEND l_s_range TO c_t_range.

ENDIF.

ENDIF.

ENDMETHOD.

METHOD zv_ist2_zv_ce_i_fiscper_bt2.

**********************************************************************
* Method for variable: zv_ce_i_fiscper_bt2 (i_step = 2)
**********************************************************************

DATA: l_s_range TYPE rsr_s_rangesid,


l_s_var_range TYPE rrrangeexit.

IF i_step = 2. "After the pop-up

READ TABLE i_t_var_range INTO l_s_var_range WITH KEY vnam = 'ZV_CE_MI_S_FISCPER_BT2'.

IF sy-subrc = 0.

Batch_2 Page 13
IF sy-subrc = 0.

CLEAR l_s_range.

CONCATENATE l_s_var_range-low(4) '001' INTO l_s_range-low.


l_s_range-high = l_s_var_range-low.

l_s_range-sign = 'I'.
l_s_range-opt = 'BT'.

APPEND l_s_range TO c_t_range.

ENDIF.

ENDIF.

ENDMETHOD.

METHOD _template.

**********************************************************************
* TEMPLATE METHOD.
* DO NOT MODIFY THIS CODE.
* FOR INDIVIDUAL METHODS, COPY THIS TEMPLATE METHOD
**********************************************************************

* DATA: l_s_range TYPE rsr_s_rangesid,


* l_s_var_range TYPE rrrangeexit.
*
* IF i_step = 2. "After the pop-up
*
* READ TABLE i_t_var_range INTO l_s_var_range WITH KEY vnam = 'ZVAR_MI_S_FISCPER'.
*
* IF sy-subrc = 0.
*
* CLEAR l_s_range.
*
* CONCATENATE l_s_var_range-low(4) '001' INTO l_s_range-low.
* l_s_range-high = l_s_var_range-high.
*
* ENDIF.
*
* APPEND l_s_range TO c_t_range.
* CLEAR: l_s_range,
* l_s_var_range.

* ENDIF.

ENDMETHOD.
ENDCLASS.
HANA Exit CLASS zcl_var_hana_badi DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .

PUBLIC SECTION.

INTERFACES if_badi_interface .
INTERFACES if_amdp_marker_hdb .
INTERFACES if_rsroa_var_hana_exit .
PROTECTED SECTION.
PRIVATE SECTION.

Batch_2 Page 14
PRIVATE SECTION.
ENDCLASS.

CLASS zcl_var_hana_badi IMPLEMENTATION.

* <SIGNATURE>--------------------------------------------------------------------------------------- +
* | Instance Public Method ZCL_BPC_CL_RSROA_HANA_EXIT->IF_RSROA_VAR_HANA_EXIT~GET_PROPERTIES
* +------------------------------------------------------------------------------------------------- +
* | [--->] I_VNAM TYPE RSZVNAM
* | [--->] I_VARTYP TYPE RSZVARTYP
* | [--->] I_IOBJNM TYPE RSIOBJNM
* | [--->] I_INFOPROV TYPE RSINFOPROV
* | [--->] I_COMPID TYPE RSZCOMPID
* | [<-->] C_IS_ACTIVE TYPE RS_BOOL
* | [<-->] C_TS_VNAM_INDEX TYPE NT_TS_VNAM_INDEX
* +-------------------------------------------------------------------------------------- </SIGNATURE>

METHOD if_rsroa_var_hana_exit~get_properties BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT.


* <SIGNATURE>--------------------------------------------------------------------------------------- +
* | Instance Public Method ZCL_BPC_CL_RSROA_HANA_EXIT->IF_RSROA_VAR_HANA_EXIT~PROCESS
* +------------------------------------------------------------------------------------------------- +
* | [--->] I_VNAM TYPE RSZVNAM
* | [--->] I_VARTYP TYPE RSZVARTYP
* | [--->] I_IOBJNM TYPE RSIOBJNM
* | [--->] I_INFOPROV TYPE RSINFOPROV
* | [--->] I_COMPID TYPE RSZCOMPID
* | [--->] I_VAR_VALUE_1 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_2 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_3 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_4 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_5 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_6 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_7 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_8 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_9 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_10 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_11 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_12 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_13 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_14 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_15 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_16 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_17 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_18 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_19 TYPE RSCHAVL
* | [--->] I_VAR_VALUE_20 TYPE RSCHAVL
* | [<-->] C_VALUE TYPE RSCHAVL
* C_IS_ACTIVE stipulates that this coding should be used to define the value of the variable

c_is_active := 'X';

IF :i_vnam = 'ZVAR_HE_S_CALDAY'
THEN
c_ts_vnam_index = SELECT 'ZVAR_HE_S_CALDAY' AS vnam, 1 as index from sys.dummy;
end if;

IF (:i_vnam = 'ZVAR_HE_S_CALDAY_FR' OR :i_vnam = 'ZVAR_HE_S_CALDAY_TO')


THEN
c_ts_vnam_index = SELECT 'ZVAR_HE_S_CALDAY' AS vnam, 1 as index from sys.dummy;
end if;

endmethod.

Batch_2 Page 15
METHOD if_rsroa_var_hana_exit~process BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT.
* Parameter c_value should specify the value of the variable.

DECLARE lv_mth NVARCHAR( 2 ) := '01';


DECLARE lv_day NVARCHAR( 2 ) := '01';

c_value:= '';

IF :i_vnam = 'ZVAR_HE_S_CALDAY'
THEN
c_value := to_dats(add_days( current_date, -1 ));
END IF;

IF :i_vnam = 'ZVAR_HE_S_CALDAY_FR'
THEN
c_value := left(:i_var_value_1,4) || lv_day || lv_mth;
END IF;

IF :i_vnam = 'ZVAR_HE_S_CALDAY_TO'
THEN
c_value := :i_var_value_1;
END IF;

ENDMETHOD.
ENDCLASS.

Batch_2 Page 16

You might also like