SAP How-to GuideSAP BW
Applicable Releases:
SAP BW 7.00 SPS 03 and forward
Version 1.0
October 2012
How To Create a solid framework for Variable andDatasource enhancment in BW
© Copyright 2012 SAP AG. All rights reserved.
No part of this publication may be reproduced or transmitted in any form
or for any purpose without the express permission of SAP AG. The
information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors
contain proprietary software components of other software vendors.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered
trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p,
System p5, System x, System z, System z10, System z9, z10, z9, iSeries,
pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390,
OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power
Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER,
OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS,
HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex,
MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and
Informix are trademarks or registered trademarks of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and other
countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either
trademarks or registered trademarks of Adobe Systems Incorporated in
the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open
Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame,
and MultiWin are trademarks or registered trademarks of Citrix Systems,
Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks
of W3C®, World Wide Web Consortium, Massachusetts Institute of
Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems, Inc., used
under license for technology invented and implemented by Netscape.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP
BusinessObjects Explorer, StreamWork, and other SAP products and
services mentioned herein as well as their respective logos are
trademarks or registered trademarks of SAP AG in Germany and other
countries.
Business Objects and the Business Objects logo, BusinessObjects,
Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other
Business Objects products and services mentioned herein as well as their
respective logos are trademarks or registered trademarks of Business
Objects Software Ltd. Business Objects is an SAP company.
Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere,
and other Sybase products and services mentioned herein as well as their
respective logos are trademarks or registered trademarks of Sybase, Inc.
Sybase is an SAP company.
All other product and service names mentioned are the trademarks of
their respective companies. Data contained in this document serves
informational purposes only. National product specifications may vary.
The information in this document is proprietary to SAP. No part of this
document may be reproduced, copied, or transmitted in any form or for
any purpose without the express prior written permission of SAP AG.
This document is a preliminary version and not subject to your license
agreement or any other agreement with SAP. This document contains
only intended strategies, developments, and functionalities of the SAP®
product and is not intended to be binding upon SAP to any particular
course of business, product strategy, and/or development. Please note
that this document is subject to change and may be changed by SAP at
any time without notice.
SAP assumes no responsibility for errors or omissions in this document.
SAP does not warrant the accuracy or completeness of the information,
text, graphics, links, or other items contained within this material. This
document is provided without a warranty of any kind, either express or
implied, including but not limited to the implied warranties of
merchantability, fitness for a particular purpose, or non-infringement.
SAP shall have no liability for damages of any kind including without
limitation direct, special, indirect, or consequential damages that may
result from the use of these materials. This limitation shall not apply in
cases of intent or gross negligence.
The statutory liability for personal injury and defective products is not
affected. SAP has no control over the information that you may access
through the use of hot links contained in these materials and does not
endorse your use of third-party Web pages nor provide any warranty
whatsoever relating to third-party Web pages.
SAP “How-to” Guides are intended to simplify the product implement-
tation. While specific product features and procedures typically are
explained in a practical business context, it is not implied that those
features and procedures are the only approach in solving a specific
business problem using SAP NetWeaver. Should you wish to receive
additional information, clarification or support, please refer to SAP
Consulting.
Any software coding and/or code lines / strings (“Code”) included in this
documentation are only examples and are not intended to be used in a
productive system environment. The Code is only intended better explain
and visualize the syntax and phrasing rules of certain coding. SAP does
not warrant the correctness and completeness of the Code given herein,
and SAP shall not be liable for errors or damages caused by the usage of
the Code, except if such damages were caused by SAP intentionally or
grossly negligent.
Disclaimer
Some components of this product are based on Java™. Any code change
in these components may cause unpredictable and severe malfunctions
and is therefore expressively prohibited, as is any decompilation of these
components.
Any Java™ Source Code delivered with this product is only to be used by
SAP’s Support Services and may not be modified or altered in any way.
Document HistoryDocument Version Description
1.00 First official release of this guide
1.01 Screen shot made bigger for better reading
Typographic ConventionsType Style Description
Example Text Words or characters quotedfrom the screen. Theseinclude field names, screentitles, pushbuttons labels,menu names, menu paths,and menu options.Cross-references to otherdocumentation
Example text Emphasized words orphrases in body text, graphictitles, and table titles
Example text File and directory names andtheir paths, messages,names of variables andparameters, source text, andnames of installation,upgrade and database tools.
Example text User entry texts. These arewords or characters that youenter in the system exactlyas they appear in thedocumentation.
<Exampletext>
Variable user entry. Anglebrackets indicate that youreplace these words andcharacters with appropriateentries to make entries in thesystem.
EXAMPLE TEXT Keys on the keyboard, forexample, F2 or ENTER.
IconsIcon Description
Caution
Note or Important
Example
Recommendation or Tip
Table of Contents
1. Business Scenario ............................................................................................................ 1
2. Background Information ................................................................................................... 1
3. Prerequisites .................................................................................................................... 1
4. Step-by-Step Procedure .................................................................................................. 24.1 Building the Enhancement Spot and BAdI’s.................................................................. 24.2 Adding the code for the BAdI to be called .................................................................... 114.3 Adding an example implementation class for each of the BAdI’s ............................. 144.4 Create a BAdI implementation for a custom variable of type user-exit .................... 174.5 Same approach used for DataSource enhancement ..................................................214.6 Add code to the classic BAdI ......................................................................................... 244.7 Using the Enhancement Spot ZCORE_DS_ENHANCEMENT .................................... 25
5. Appendix ....................................................................................................................... 26
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 1
1. Business ScenarioYou are implementing BW. As with many SAP applications the possibility to enhance the standardfunctionality is built into the application. From your knowledge, you are aware of the pitfalls that canarise from allowing developer’s unmonitored access to areas like user exits and BADI’s.Nonetheless, enhancements are required as part of many BW implementations.You intended to present only one method for enhancing the functionality in conjunction with theimplementation of BW – further the following requirement should be full filled
Each development project must be independent from the othersErrors in one piece of development may not endanger other sections already liveOne project must be able to be developed independent of the others
2. Background InformationIn BW and attached source systems, a range of user exits and BADI’s are almost obligatory toimplement and use:
Custom Variable exitsEnhancement of DataSources (User exit or BADI) in all Source systemMFLOW enhancement in CRM…
Many of these enhancements only allows for ONE piece of code. Without further action baddevelopment in this piece of code may jeopardize projects and developments already live.In the past, many different methods have been used to circumvent the problem:
Naming convention that allows for dynamic calls to pieces of code.Tables with the ID and the corresponding class/method or include.
Most new enhancements from SAP are using the enhancement framework. Using the proposedmethodology here, all existing enhancements are moved into using this same method. This wayonly ONE method of enhancement is presented for the developers!The background for this paper is BW, but the framework and steps here can be used for anyenhancement where multiple implementations are required in ONE piece of code.What we do is to create an enhancement spot. This enhancement spot can be used in one or moreenhancement implementations – These can be used to group together BAdI implementations thatlogical belongs together or where dependencies exist.
3. PrerequisitesABAP-AS 7.00 or higher
Provide information about:Enhancement framework at help.sap.comKnowledge of ABAP development is a prerequisite for the implementation of the BADI’screated in the guide. Step-by-Step must be adjusted to fit with the naming convention in theproject.At various points during the implementation the SAP will request a Package and TransportRequest. This Step-By-Step guide does not deal with this! It’s expected that the assignmentto the package and transport request is known by the developer.
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 2
4. Step-by-Step ProcedureAs an example we will use the user-exit for custom variable. This will require us to build oneenhancement point with two BADI’s.Secondly we will implement the static code required to use the enhancement point in the SAPprovided user-exit.Third we will build an actual implementation of the enhancement point – This step-by-step is theguide the developers in the project will have to follow in order to implement the actual “user-exit”.The general naming convention that is used here is XXXX, representing the identification of a namespace used to differentiate the different project implemented in the BW and adjacent systems
Enhancement Spot:Z<XXXX>_<Free description>
Enhancement ImplementationZ<XXXX>_<Free description>_<####>
Interface:ZIF_<XXXX>_<Free description>
Class:ZCL_<XXXX>_<Free description>
BAdI:Z<XXXX>_<Id of the object enhanced>
BAdI class:ZCL_<XXXX>_<Id of the object enhanced>
When everything is done the implementation is visible going into the SE18 and the enhancementspot of either DataSource or Variables.
4.1 Building the Enhancement Spot and BAdI’s...
1. Go to Transaction SE18 BAdI Builder: Initial screen for Definitions and make sure the radiobottom is on Enhancement Spot - add the name you intend to use for the Enhancement Spot
Add description of Enhancement Spot in the popup
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 3
2. Create BAdI definition for variable exit call i_step = 0, 1 and 2 bypressing the Create bottom on the Enh. Spot Element Definitions tab
Add the name and description in the pop-up
Make sure that this BAdI only can have one implementation for the BAdI instance byremoving the flag in Multiple use
For the instantiation part, choose Reusing Instantiation
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 4
3. Create the interface that are to be used for the BAdI by first opening the newly created BAdIand dbl-click on the Interface node
The Interface screen is shown. Add the name of the interface you intend to use for the BAdI –Hit the Change bottom
As the interface does not exists at current a popup will prompt you to create this interface –Choose yes
4. First make sure that the general BAdI interface is present in the created interface by lookingfor the interface IF_BADI_INTERFACE on the Interface tab
5. Add the method for processing the variable
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 5
6. Adding the Parameters by pressing the Parameter bottom
Add the parameters required (Please note that the full interface include more interfacevariables, these are only very rarely used and excluded here)!
7. Add exceptions by pressing the Exception tab
and add only one exception. The call of the user-exit will not differ between the exceptions,hence having only one and a suitable message pushed from the code will do it the trick
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 6
8. Optional: Add type pool RS to the interface on the Properties tab. This interface includesconstants that can be used to selection option
CONSTANTS:BEGIN OF rs_c_range_sign,
including TYPE rs_s_range-sign VALUE 'I',excluding TYPE rs_s_range-sign VALUE 'E',
END OF rs_c_range_sign,
BEGIN OF rs_c_range_opt,initial TYPE rs_s_range-opt VALUE space,equal TYPE rs_s_range-opt VALUE 'EQ',less TYPE rs_s_range-opt VALUE 'LT',
lessequal TYPE rs_s_range-opt VALUE 'LE',greater TYPE rs_s_range-opt VALUE 'GT',
greaterequal TYPE rs_s_range-opt VALUE 'GE',between TYPE rs_s_range-opt VALUE 'BT',
pattern TYPE rs_s_range-opt VALUE 'CP', notequal TYPE rs_s_range-opt VALUE 'NE', notbetween TYPE rs_s_range-opt VALUE 'NB', notpattern TYPE rs_s_range-opt VALUE 'NP',
END OF rs_c_range_opt.
9. Activate the interface by pressing the Activate bottom
10. Return to the BAdI definition using Back
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 7
11. Create a filter definition for the BAdI by going to the Enh. Spot Element Definition tab, Rightmouse bottom (RMB) click on the BAdI ZCORE_VAR_USEREXIT_FILL and choose CreateFilter
Fill values in the popup. Giving the filter a name, Choose Character type C and a description.You can choose automatic check from the dictionary, but this will prevent you from usingwildcards in the filter selection.
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 8
12. Create another BAdI for processing the i_step = 3, by pressing the Create bottom on the Enh.Spot Element Definition tab
And filling the information required into the popup
Make sure that this BAdI only can have one implementation for the BAdI instnace byremoving the flag in Multiple use
For the instantiation part, choose Reusing Instantiation
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 9
13. Create the interface that are to be used for the BAdI by first opening the newly created BAdIand dbl-click on the “Interface” node
The Interface screen is shown. Add the name of the interface you intend to use for the BAdI –Hit the Change bottom
As the interface does not exists at current a popup will prompt you to create this interface –Choose yes
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 10
14. Add Method, Parameter and exception following the step 5, 6 and 7 in this section
Parameters
Exceptions
15. Save and Activate the Interface
Return to the Enhancement Builder16. Add a filter for the BAdI ZCORE_VAR_USEREXIT_CHECK, by RMB- click on the BAdI and
choose Create Filter
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 11
Fill the values of the popup
17. Activate the enhancement spot by pressing the Activate bottom. The enhancement spot isnow ready to be used
4.2 Adding the code for the BAdI to be called...
1. Locate the User-exit in SPRO and pressing the Execute bottom
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 12
2. Create a project for the user-exit by entering a name (In almost all cases this is already done,watch for this) and pressing Create
Enter a description and Save
3. Add the Enhancement assignment for the Variable User-Exit by pressing the Enhancementassignment bottom
Add the Enhancement: RSR00001 and press Save
4. Add the necessary code bySwitching to the components of the Enhancement by pressing the Components bottom
Now dbl-click the EXIT_SAPLRRSO0_001
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 13
Dbl-Click on the INCLUDE ZXRSRU01.
If you receive the following warning message, press the “enter key”
If you receive the following pop up window, select “Yes”
Add the code listed in Appendix A to the INCLUDE ZXRSRU01.
5. Return to the Component view and activate the enhancement using the Activate bottom. Thiswill ensure that the SAP standard software calls the new enhancement spot
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 14
4.3 Adding an example implementation class for each of theBAdI’s
Adding an example class makes it possible for you to supply a “template” on how the BAdI must beimplemented. This is performed in the Enhancement Builder TX SE18....
1. Create an Example Class for the BAdI ZCORE_VAR_USEREXIT_FILLby going to the Enh. Spot Element Definition tab, Right mouse bottom (RMB) click on the BAdIZCORE_VAR_USEREXIT_FILL and choose Create Impl. Example Class
Fill the values into the popup
As the Class does not exist – Choose yes to confirm the creation
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 15
2. Add the code required to process the variableAs the class already is equipped with the interfaces required by the BAdI (Can be checked inthe Interface tab) – Press the Code bottom
Add the code from Appendix B, Save and Return to the Class maintenance screen
3. Activate the example class by pressing the Activate Bottom
4. Return to the BAdI definition by pressing Back
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 16
5. Create an Example Class for the BAdI ZCORE_VAR_USEREXIT_CHECKby going to the Enh. Spot Element Definition tab, Right mouse bottom (RMB) click on the BAdIZCORE_VAR_USEREXIT_CHECK and choose Create Impl. Example Class
Fill the values into the popup
As the Class does not exist – Choose yes to confirm the creation
6. Add the code to verify the values entered in the variable input screenAs the class already is equipped with the interfaces required by the BAdI (Can be checked inthe Interface tab) the only thing needed is to add the code – Press the Code bottom
Add the code from Appendix C, Save and Return to the Class maintenance screen
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 17
7. Activate the example class by pressing the Activate Bottom
8. Return to the BAdI definition by pressing Back
4.4 Create a BAdI implementation for a custom variable oftype user-exit
In this section we do the work that is required to implement custom code for a variable of type user-exit. Therefore it is important for a short time to revisit the concept behind the enhancement spot.The framework proposed here is referenced as the ”New BADI”. Before implementing the BAdI’swe just defined, we need an enhancement implementation. It’s possible to have move than oneenhancement implementation.Use enhancement implementations to group similar BAdI implementation together pr. Project. Inour example we will implement one enhancement implementation and create one BAdIimplementation pr. BAdIAs a surggestion, create either one enhancement implementation pr. BW application or going all inwith one pr. BAdI implementation required. The organization chosen should reflect the build donein the AWB....
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 18
1. An Enhancement Implementation and consequently the BAdI implementation is createdusing the transaction code SE19. Create an implementation by writing the enhancement spotnewly created in the Enhancement spot field and press the Create Impl. bottom
Filling the values as pt. the naming convention into the popup
2. Optional: Directly creating the BAdI from the popupAdd the name of the BAdI implementation and the corresponding name of the ABAP-OOclass that will contain the code and choose the BAdI definitionZCORE_VAR_USEREXIT_FILL
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 19
Next popup gives the option to create the Implementation Class either asEmpty Class – Creates a Class with the require interface already addedCopy example Class – Copy the example class that you can alterInherit from example Class – (Not possible in our example as the example class isdefined as Final) can be used to reuse methods and attributes from the example classin multiple implementations
3. Create the implementation Class by choosing to copy the example class.
This will bring you to the Enhancement Implementation maintenance screen
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 20
4. Change the implementation Class by Dbl-click on the Implementation Class under the BAdI inthe BAdI implementation screen and pressing the Change bottom
5. Change and Activate the Class (We do not change anything, we used to the code for theexample class… yes I know bad example)
6. Add a filter to the BAdI implementationBy dbl-clicking the Filter Val.” Node under the BAdI in the BAdI implementation screen andpressing the Create Combination
7. Choose the Combination that is created and press the Change Filt. Val. Bottom
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 21
8. Set the filterIn our case we would like this BAdI implementation to be called for all variables that follows aspecific naming convention…
9. Activate the Enhancement Implementation
10. Maintain the Enhancement Implementation using SE19
4.5 Same approach used for DataSource enhancementIn general two different approaches are used when enhancing a DataSource in the Source system,the user exit enhancement RSAP0001 and the classical BAdI RSU5_SAPI_BADI. SAP recommendsthe use of the BAdI. The work and code required are independent of method chosenAppendix D should be added to includes:
ZXRSAU01ZXRSAU01ZXRSAU03
And Appendix E includes:ZXRSAU04
The Step-By-Step will be somewhat shortened a bit as the full explanation is in the precedingsections...
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 22
1. Create a custom enhancement spot via TX SE18
2. Create BAdI definition by pressing the Create bottom
Using the same settings for Multiple Use and Instance creation mode as 4.1
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 23
3. Reuse the interface from the classical BAdI in this new BAdI – Use TX SE24 to get the valuesfrom IF_EX_RSU5_SAPI_BADI and create ZIF_CORE_DS_ENHANCEMENT
Add the method DATA_TRANSFORM
Add the method HIER_TRANSFORM
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 24
4. Create a filter that should be used to filter on Datasource
It’s highly unlikely that an enhancement can be reused between Datasource, hence wechoose to have the filter values verified against the dictionary
5. Activate the Enhancement spot
4.6 Add code to the classic BAdI...
1. Create the implementation by using TX SE18 Display the BAdI RSU5_SAPI_BADI
And choosing [Implementation] [Create]
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 25
Add a description
2. Create the implementation classGo to the Interface tab and Dbl-Click on the method DATA_TRANSFORM. This will bring youdirectly to the code of the method – Add the code from appendix D and activate
Do the same for the method HIER_TRANSFORM using the code of append E3. Activate the classic BAdI implementation, this will ensure the code is called
4.7 Using the Enhancement SpotZCORE_DS_ENHANCEMENT
Refer to section 4.44. Create an Enhancement Implementation to be used for the BAdI implementation5. Inside the Enhancement Implementation create a BAdI implementation
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 26
5. What additional can be doneThis section includes some advice on what can be done in addition to the implementation in the ste-by-step procedure.
5.1 Adding a default class to the BADI’sOne of the feature of a the new BADI concept is the possibility to have a default CLASS
This feature can be used to convert existing exit implementations into the new concept. If now BADIcan be found using the filter. The BADI is implemented based on this FALLBACK class. This classactive method must now be programmed to call the legacy implementation....
1. An example could be to call the old USER-EXIT for DataSource enhancements:2. In the DATA_TRANSFORM of the fallback class add calls to the three flat DataSource exit
function modules:EXIT_SAPLRSAP_001EXIT_SAPLRSAP_002EXIT_SAPLRSAP_003
3. In HIER_TRANSFORM callEXIT_SAPLRSAP_004
Now you can deactivate the CMOD enhancement project. The classic BADI will call the newEnhancement Concept – If now new BADI can be found a BADI based on the example class will behanded to the framework and the code of the CMOD enhancement will be called.You are left with only one concept!The same can be done with Variable exit – but do NOT call the Function moduleEXIT_SAPLRRS0_001 as this holds the active implementation of the new enhancement spot andyou will get an infinite loop.
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 27
6. AppendixFollowing the code is referenced in this document
Appendix A – Code of the user-exit include ZXRSRU01*&---------------------------------------------------------------------**& Include ZXRSRU01*&---------------------------------------------------------------------*
DATA: lr_badi_fill TYPE REF TO zcore_var_userexit_fill, lr_badi_check TYPE REF TO zcore_var_userexit_check, lr_exc TYPE REF TO cx_root.
TRY.IF i_step = 3.
** The BADI for checking the varaibles entered by the user in the** input screen is check in i_step = 3. The check is called using** the technical name of the query
GET BADI lr_badi_check FILTERS zcore_var_userexit_check_filter = i_s_rkb1d-compid.
CALL BADI lr_badi_check->do_check_variable_inputEXPORTING
iv_vartyp = i_vartyp iv_iobjnm = i_iobjnm is_cob_pro = i_s_cob_pro is_rkb1d = i_s_rkb1d it_var_range = i_t_var_range
EXCEPTIONS again = 1
OTHERS = 2.CASE sy-subrc.WHEN 1.CALL FUNCTION 'RRMS_MESSAGE_HANDLING'EXPORTING
i_class = sy-msgid i_type = sy-msgty i_number = sy-msgno i_msgv1 = sy-msgv1 i_msgv2 = sy-msgv2 i_msgv3 = sy-msgv3 i_msgv4 = sy-msgv4.
RAISE again.WHEN OTHERS.
** It's expected that the programmer of the BAdI have done** the message handling himself
RAISE again.ENDCASE.
ELSE.GET BADI lr_badi_fill
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 28
FILTERS zcore_var_userexit_fill_filter = i_vnam.
CALL BADI lr_badi_fill->do_process_variableEXPORTING
iv_vnam = i_vnam iv_vartyp = i_vartyp iv_iobjnm = i_iobjnm is_cob_pro = i_s_cob_pro is_rkb1d = i_s_rkb1d it_var_range = i_t_var_range iv_step = i_step
IMPORTING et_var_range = e_t_range
EXCEPTIONS error = 1
OTHERS = 2.CASE sy-subrc.WHEN 1.CALL FUNCTION 'RRMS_MESSAGE_HANDLING'EXPORTING
i_class = sy-msgid i_type = sy-msgty i_number = sy-msgno i_msgv1 = sy-msgv1 i_msgv2 = sy-msgv2 i_msgv3 = sy-msgv3 i_msgv4 = sy-msgv4.
RAISE error.WHEN OTHERS.
** It's expected that the programmer of the BAdI have done** the message handling himself
RAISE error.ENDCASE.
ENDIF.CATCH cx_badi_multiply_implemented
cx_badi_not_implemented cx_badi_initial_reference INTO lr_exc.
CALL FUNCTION 'RS_EXCEPTION_TO_SYMSG'EXPORTING
i_r_exception = lr_exc i_deepest = rs_c_true.
CALL FUNCTION 'RRMS_MESSAGE_HANDLING'EXPORTING
i_class = sy-msgid i_type = sy-msgty i_number = sy-msgno i_msgv1 = sy-msgv1 i_msgv2 = sy-msgv2 i_msgv3 = sy-msgv3 i_msgv4 = sy-msgv4* I_INTERRUPT_SEVERITY = 16
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 29
* I_LANGU = SY-LANGU* I_SAPGUI_FLAG = ' '* I_SUPPRMESS =* I_CUMULATE = RS_C_FALSE* I_PROBCLASS =
.RAISE error.
ENDTRY.
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 30
Appendix B – Code of methodZIF_CORE_VAR_USEREXIT_FILL~DO_PROCESS_VARIABLE in the example classmethod ZIF_CORE_VAR_USEREXIT_FILL~DO_PROCESS_VARIABLE.
data: ls_var_range type RRS0_S_VAR_RANGE, ls_range type RRRANGESID.
** This BAdI can be implemented for iv_step = 0, 1, or 2. Best do a check** on the iv_step as we only what to process this for iv_step = 2.check iv_step = 2.
** This example class build in order to allow for a variable to be created** indication by use of the tehcnical name this extend of the interval** from todays date.
** this check should not be necessarycheck iv_vnam(15) = 'CORE_CCI_MN_01_'.
data: lv_c_offset(4) type c, lv_i_offset type i, lv_date type d.
** The characters from 16-20 must be numeric lv_c_offset = iv_vnam+15(4).
try.move lv_c_offset to lv_i_offset.
catch CX_SY_CONVERSION_NO_NUMBER.** This error message is generic and give no clue on why the name** is invalid but as an example this will serves a purpose -** Please be sure to add correct and decriptive error message that** can be understood by the end-users
message e107(RS_EXCEPTION) with iv_vnamraising error.
endtry.
lv_date = sy-datum.
ls_range-sign = rs_c_range_sign-including. ls_range-opt = rs_c_range_opt-between. ls_range-high = lv_date.** Use the offset lv_date = lv_date - lv_i_offset. ls_range-low = lv_date.append ls_range to et_var_range.
endmethod.
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 31
Appendix C – Code of methodZIF_CORE_VAR_USEREXIT_CHECK~DO_CHECK_VARIABLE_INPUT in theexample class for the BAdI ZCORE_VAR_USEREXIT_CHECKMETHOD zif_core_var_userexit_check~do_check_variable_input.
DATA: ls_var_range TYPE rrrangeexit, lv_var_ok TYPE rs_bool, lv_query TYPE rszcompid.
** Check that the query is correct... Not needed but shows where** to find the query information lv_query = is_rkb1d-compid.CHECK lv_query(5) = 'ZCORE'.
** Always initiate the variable lv_var_ok = rs_c_true.LOOP AT it_var_range INTO ls_var_range.CHECK lv_var_ok = rs_c_true.CASE ls_var_range-iobjnm.WHEN '0CALDAY'.IF ls_var_range-opt <> rs_c_range_opt-between.
lv_var_ok = rs_c_false.ENDIF.
ENDCASE.ENDLOOP.
IF lv_var_ok = rs_c_false.MESSAGE e324(xms_adm) RAISING again.
ENDIF.
ENDMETHOD.
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 32
Appendix D – Code of method IF_EX_RSU5_SAPI_BADI~DATA_TRANSFORM inthe implementation class (ZCL_IM_CORE_DS_CLASSIC) of the BAdIRSU5_SAPI_BADImethod IF_EX_RSU5_SAPI_BADI~DATA_TRANSFORM.
DATA: lr_badi_ds_data TYPE REF TO zcore_ds_enhancement, ls_messages TYPE balmi, lr_exc TYPE REF TO cx_root.
TRY.GET BADI lr_badi_ds_data
FILTERS zcore_ds_enhancement = i_datasource.
CALL BADI lr_badi_ds_data->data_transformEXPORTING
i_datasource = i_datasource i_updmode = i_updmode i_t_select = i_t_select i_t_fields = i_t_fields
CHANGING c_t_data = c_t_data c_t_messages = c_t_messages.
CATCH cx_badi_not_implemented cx_badi_multiply_implemented cx_badi_initial_reference.** no error handling required
CATCH cx_root INTO lr_exc.CALL FUNCTION 'RS_EXCEPTION_TO_SYMSG'EXPORTING
i_r_exception = lr_exc i_deepest = rs_c_true.
MOVE-CORRESPONDING syst TO ls_messages.APPEND ls_messages TO c_t_messages.
ENDTRY.ENDMETHOD.
How To Create a solid framework for Variable and Datasource enhancement in BW
November 2012 33
Appendix E – Code of method IF_EX_RSU5_SAPI_BADI~HIER_TRANSFORM inthe implementation class (ZCL_IM_CORE_DS_CLASSIC) of the BAdIRSU5_SAPI_BADIMETHOD if_ex_rsu5_sapi_badi~hier_transform.
DATA: lr_badi_ds_hier TYPE REF TO zcore_ds_enhancement, ls_messages TYPE balmi, lr_exc TYPE REF TO cx_root.
TRY.GET BADI lr_badi_ds_hier
FILTERS zcore_ds_enhancement = i_datasource.
CALL BADI lr_badi_ds_hier->hier_transformEXPORTING
i_datasource = i_datasource i_s_hieflag = i_s_hieflag i_s_hier_sel = i_s_hier_sel i_t_langu = i_t_langu
CHANGING c_t_hietext = c_t_hietext c_t_hienode = c_t_hienode c_t_foldert = c_t_foldert c_t_hieintv = c_t_hieintv c_t_messages = c_t_messages.
CATCH cx_badi_not_implemented cx_badi_multiply_implemented cx_badi_initial_reference.** no error handling required
CATCH cx_root INTO lr_exc.CALL FUNCTION 'RS_EXCEPTION_TO_SYMSG'EXPORTING
i_r_exception = lr_exc i_deepest = rs_c_true.
MOVE-CORRESPONDING syst TO ls_messages.APPEND ls_messages TO c_t_messages.
ENDTRY.
ENDMETHOD.
www.sap.com/contactsap
www.sdn.sap.com/irj/sdn/howtoguides