Thursday, August 14, 2014

Modularize BEx Exit Variables in just 5 easy Steps

Key Concept

SAP provides a single user exit where we need to write code for the exit variables . Over the lifecycle of the BW as the requirements of Exit variables evolve this exit become a very long piece of linear coding which is very difficult to maintain and troubleshoot . This article describes the method to modularize coding of exit variables that are easy to maintain and troubleshoot in a distributed development environment .


INTRODUCTION: 
SAP delivered source system user-exits allow us to calculate values for BEx Variables with processing type “Customer Exit”. With CMOD you can activate Enhancement RSR00001 “BW: Enhancements for global variables in reporting”. In Function Module EXIT_SAPLRRS0_001 you have to write code within Include ZXRSRU01.



For example  in a productive system it would look like 


It is quite common having more than one thousand rows of ABAP code in the same Include, written by different developers. Transport management can be challenging especially when you have large number of BEx Variables and different people or teams are working on the user-exits. Object may be locked by someone else while you are trying to incorporate an urgent fix to resolve a production issue. This leads to reversal of code and retesting of the variables / code which are redundant and unproductive. 

How it Works


The main logic here proposed is having a dynamic CALL FUNCTION to a different Function Module for each BEx Variable.
The name of the Function module for variable exit should have a naming convention as follows,

ZVAREXT_XYZ_ABC

 XYZ = Infoobject Name,

 ABC = Variable Name

So a exit variable ZVAR2 on info object  ZME_CUST would have the Exit Function Module name is as follows,
ZVAREXT_ZME_CUST_ZVAR2


Below are the 5 Steps to modularize this EXIT



1.      Create a Variable 'ZVAR2', of type Customer Exit on top of the Infoobject 'ZME_CUST' in the query              
"ZQRY_DEMO_EXT" . In the query designer 




2.     Go to tcode, SE37 - ABAP Function Modules create a new Function Group by selecting the menu options,

Goto -> Function Groups -> Create Group







In Global Data of the include "LZBEXVAR_001TOP" make the following declarations,



3.     Create a Function Module  ZVAREXT_ZME_CUST_ZVAR2 (As per the naming convention prescribed above)   in this function group with  the following requirements concerning importing and exporting parameters
    Note – Note that these Import and export parameter are the same as of exit Enhancement RSR00001

Importing Parameters,





Exporting Parameters,














4.     Within each Function Module you can code the same logics you would have placed in Include ZXRSRU01.


For example in this case we have put the logic that it ZME_CUST  should be EQ 2 



After coding the required logic activate our function module "ZVAREXT_ZME_CUST_ZVAR2".

5.  Replace the code in Include ZXRSRU01 with the below code,

DATA: FM_NAME TYPE c LENGTH 100,
          CHAR_NAME 
TYPE c LENGTH 20,
          VAR_NAME 
TYPE RSZVNAM,
          tb_RANGESID 
TYPE RSR_T_RANGESID.

VAR_NAME = I_VNAM.
CHAR_NAME = I_IOBJNM.

CONCATENATE 'ZVAREXT' '_' CHAR_NAME '_' VAR_NAME INTO FM_NAME.

 TRY.

CALL FUNCTION FM_NAME
  
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
 
IMPORTING
   E_T_RANGE           =  E_T_RANGE.

  CATCH CX_SY_DYN_CALL_ILLEGAL_FUNC
          CX_SY_DYN_CALL_ILLEGAL_TYPE
          CX_SY_DYN_CALL_PARAM_MISSING
          CX_SY_DYN_CALL_PARAM_NOT_FOUND.
  ENDTRY.




In the above code the following logic is done,

a.     The Function module name is obtained by concatenating 'ZVAREXT', base Infoobject name and the Variable name.
b.    The existence of the exit function module is checked using the function "FUNCTION_EXISTS".
And if the Exit Function exists, it is executed by passing the required parameters.

Check working of the Varible :
              Go to the tcode: RSRT, and execute the query after the query name as" ZQRY_DEMO_EXT",



As per the above query result, since in the function module for the variable "ZVAR2", the Customer characteristic is filtered only to "C002", only that particular value is displayed.
When adding a new exit variable all we need to do is create a new function module with the prescribed naming conventions

ZVAREXT_XYZ_ABC

 XYZ = Infoobject Name,

 ABC = Variable Name

CONCLUSION:
This was different developers are able to create separate function modules for different variable variables streamlining the development and maintenance. 


No comments:

Post a Comment