how to link bex queries via vb exits

Upload: piedone64

Post on 03-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 How to Link BEx Queries via VB Exits

    1/12

    How to

    Link BEx Queries

    via VB ExitsBUSINESS INFORMATION WAREHOUSE

    ASAP How to Paper

    SAP (SAP America, Inc. and SAP AG) assumes no responsibility for errors or omissions in these materials.

    These materials are provided as is without a warranty of any kind, either express or implied, including but not limited to, the impliedwarranties of merchantability, fitness for a particular purpose, or non-infringement.

    SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages thatmay result from the use of these materials.

    SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within thesematerials. SAP has no control over the information that you may access through the use of hot links contained in these materialsand does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages.

  • 7/28/2019 How to Link BEx Queries via VB Exits

    2/12

    HOWTO LINKBEXQUERIESVIAVBEXITS

    Applicable Releases: BW 2.0B, 2.1C, 3.0A

    December 2001

    1998 SAP AMERICA, INC. AND SAP AG TABLEOF CONTENTS

  • 7/28/2019 How to Link BEx Queries via VB Exits

    3/12

    HOWTO LINKBEXQUERIESVIAVBEXITS

    1 Business Scenario

    You want to display several independent graphics for one BEx query, for example one separate

    graphic per column (see screenshot 1 below). Those graphics should be dynamic that means,whenever you filter on specific calendar day values in the query, the graphics should be adaptedaccordingly.

    In case of one graphic (covering all columns), this is typically not a problem. You would just choosefrom the BEx toolbar the following option: Layout => Attach Chart.

    However, there are a few limitations to this feature. First of all, the chart will display all data points inthe current query display (at least, after each query refresh): Including all columns, and including thetotals row (where available). Furthermore, if you decide to add a second chart for the same query(again, via Layout => Attach Chart), you will notice that the first chart now is no longer connected tothe BEx context, that means it will no longer dynamically adapt to changing result areas. Only thesecond chart now will be the only chart truly connected to the BEx context. You cannot attach twocharts dynamically to the same query with conventional methods.

    2 Introduction

    The following step-by-step guide describes how you can achieve the desired results (displayedabove), using some Visual Basic (VB) coding within your workbook. Only minimal coding know-howis required. User-Exits provided by SAP will be used, assuring maximum upgrade-ability for yousolution.

    In summary, you will need to perform the following steps:

    o Create a workbook, with two worksheets

    o Insert the same query three times into the workbook

    o Name the filter cells for navigation

    o Include some VB coding

    o Test and execute your query / workbook

    2001 SAP AMERICA, INC. AND SAP AG

  • 7/28/2019 How to Link BEx Queries via VB Exits

    4/12

    HOWTO LINKBEXQUERIESVIAVBEXITS

    Careful! Careful! Careful! Careful! Careful! Careful! Careful! Careful! Careful! Careful! Careful!

    Before diving into the step-by-step solution, I want to give you a heads-up about some limitationsand risks. In general, it is recommended to keep the VB coding within workbooks to a minimum. Butif you decide to take advantage of it, please absolutely make sure that you rely 100% on user exitsprovided by SAP. Failure to do so, will lead to a nightmare in terms of ongoing system maintenance,since every system upgrade and every system patch (both back-end as well as BEx) can lead to BExlayout changes, and you will be forced to perform significant system tests before every upgrade orpatch application. In the past, I have observed projects where the customer actually refused toimport any new patches, just to avoid the re-testing of the VB coding.

    Even with the standard SAP user exits, there are a few pitfalls that you need to be aware of, mostlyrelated to performance.

    The VB code by its nature can slow down query execution.

    Some scenarios (like the one described in this paper) require the execution of mult iple

    queries in the background, hidden from the user, and can therefore result in longer executiontimes.

    Occassionally, there is the temptation to display as much data as possible on a single

    worksheet, and to use VB coding to further restrict the data. Due to the very high number ofrows to be formatted and transported to the front-end this approach can lead to performanceproblems.

    Besides performance considerations, VB coding typically only supports limited navigationfeatures (you will see this later in the provided example).

    2001 SAP AMERICA, INC. AND SAP AG

  • 7/28/2019 How to Link BEx Queries via VB Exits

    5/12

    HOWTO LINKBEXQUERIESVIAVBEXITS

    3 The Step By Step Solution

    Prepare the Worksheet, and insert Queries

    1. In the BW BEx Analyzer, open anew workbook. Make sure thatthis workbook contains twoworksheets. You can giveindividual names to thoseworksheets (LS1 and LS2 inour example) by using Excelfunctionality: Format =>Sheet=> Rename.

    2. Insert your desired query intothe worksheet LS2, at thedesired position. (You can dothis via the BEx macro toolbar:Tools => Insert Query.) In our

    example, we used the SAPstandard technical contentquery 0BWTC_C10_Q015.

    2001 SAP AMERICA, INC. AND SAP AG

  • 7/28/2019 How to Link BEx Queries via VB Exits

    6/12

    HOWTO LINKBEXQUERIESVIAVBEXITS

    3. Now insert the same query twomore times, this time inworksheet LS1. Make sure thatthe queries cannot overlapduring navigation. Besides this,

    you do not have to pay toomuch attention to the layout ofworksheet LS1: Later, it will bemade invisible for the useranyway.Save the workbook (eitherlocally to a file, or to a role).

    4. The two queries in LS1 willserve as foundation for the

    charts. Since you want to havetwo charts, with each chartfocusing on exactly one column,we need to restrict the queryoutput for the two queries onLS1 to one column each(Overall time and Overallnumber in our example). Youcan filter on a specific columnby double-clicking on thecolumn header, or single-clicking on the column header

    and choosing from the contextmenu Keep as filter value.

    5. Assign names to the filter cells,which you want to connect.Using Excel functionality, clickon the relevant cell, then type acell name into the Excel NameBox (left end of formula bar),and press Enter.Repeat this for the remainingtwo queries. In our example,

    we will be linking filtering forthe calendar day. (On LS2,calendar day, cell B16 wasnamed).We choose the following threecell names:- FilterValue01 for 1st query inLS1

    2001 SAP AMERICA, INC. AND SAP AG

  • 7/28/2019 How to Link BEx Queries via VB Exits

    7/12

    HOWTO LINKBEXQUERIESVIAVBEXITS

    - FilterValue02 for 2nd query inLS1- FilterValue00 for query in LS2

    6. Now attach one chart each forthe queries in LS1. You do thisby selecting the respectivequery, and then executinglayout => attach chartfrom theBEx toolbar.

    You can change the layout ofthe charts, and e.g. include atitle or suppress the legend.Also you might want tosuppress the totals rows of thequeries in LS1, if you do notwant to have them included inthe charts (select query, andthen from the context menu:Allchars => Suppression of totalsrow => Always).

    2001 SAP AMERICA, INC. AND SAP AG

  • 7/28/2019 How to Link BEx Queries via VB Exits

    8/12

    HOWTO LINKBEXQUERIESVIAVBEXITS

    7. Actually you want to have bothcharts displayed in worksheetLS2 (and not LS1). Therefore,right mouse click on each chart,and select Location => As

    object in => LS2. This will movethe charts to LS2.Once you have both charts inLS2, feel free to move themaround in your worksheet to aposition that you feelcomfortable with.

    Link the Queries in the Workbook

    8. With your workbook opened,from the Excel menu chooseTools => Macro => VisualBasic Editor.

    2001 SAP AMERICA, INC. AND SAP AG

  • 7/28/2019 How to Link BEx Queries via VB Exits

    9/12

    HOWTO LINKBEXQUERIESVIAVBEXITS

    9. This function will open the ExcelVisual Basic Editor, and takeyou straight to a BEx user exit:Sub SAPBEXonRefresh(queryID

    As String, resultArea As Range).

    This exit is always executedwhen you refresh a query. Andthis is the exit, where you willperform all of yourprogramming (in the next step).

    10. Enter the VB coding. For moreinformation on the available

    BW macros please refer to theBW online documentation. Inaddition, please see OSS /SapNet consulting notes (e.g.note 395272 provides specificinformation on the macroSAPBEXcopyFilterValueutilized in this example).Note: The sample coding usedhere is listed once more at theend of this How-To-Guide, inthe appendix.

    11. You are now finished! Selectthe query in LS2, and push theRefresh button on the BExtoolbar. If you pay closeattention, you will notice thatExcel will give three status-messages (one for eachquery), when executing.

    2001 SAP AMERICA, INC. AND SAP AG

  • 7/28/2019 How to Link BEx Queries via VB Exits

    10/12

    HOWTO LINKBEXQUERIESVIAVBEXITS

    12. For testing purposes, filter ona few date values in your mainquery (query in LS2). You cando so, for example, bymarking the rows and via right

    mouse click selecting from thecontext menu Keep as FilterValue. When finished, thecharts will automatically beadapted to the dates selected.

    13. As a finishing touch, you

    should hide the worksheet LS1from the user. You can do thisvia standard Excelfunctionality. Open up sheetLS1, and from the Excel menuchoose: Format => Sheet =>Hide.

    A final Warning

    2001 SAP AMERICA, INC. AND SAP AG

  • 7/28/2019 How to Link BEx Queries via VB Exits

    11/12

    HOWTO LINKBEXQUERIESVIAVBEXITS

    14. Try the following: On yourmaster query (in LS2), selectthe respective filter cell (here:calendar day) and choosefrom the BEx context menu:

    Remove Drilldown. You willsee that the charts do notchange, even though theresult lines are not displayedanymore. This is because youimplemented only the logic tolink the filter cells you didnot implement any logic tolink the drilldown states. Youwould need an additionalmacro for this, which isdescribed in the BW online

    documentation.Also note, if you would filteron another free characteristic,the results in the main querywould change, but, the chartswould not adapt accordinglysince in our example we onlylinked one specific set of filtercells (calander day)!

    2001 SAP AMERICA, INC. AND SAP AG

  • 7/28/2019 How to Link BEx Queries via VB Exits

    12/12

    HOWTO LINKBEXQUERIESVIAVBEXITS

    4 Appendix

    Visual Basic Coding, used in this exampleSub SAPBEXonRefresh(queryID As String, resultArea As Range)

    ' *** Only in case of master query refresh ***

    If queryID = "SAPBEXq0003" Then

    ' *** Assign values ***

    Dim myWorksheet As Worksheet

    Set myWorksheet = ThisWorkbook.Worksheets("LS1")

    Set filterVal1 = myWorksheet.Range("FilterValue01")

    Set filterVal2 = myWorksheet.Range("FilterValue02")

    Set myWorksheet = ThisWorkbook.Worksheets("LS2")

    Set filterVal0 = myWorksheet.Range("FilterValue00")

    ' *** Excecute Macros ***

    Run "SAPBEX.XLA!SAPBEXcopyFilterValue", filterVal0, filterVal1Run "SAPBEX.XLA!SAPBEXcopyFilterValue", filterVal0, filterVal2

    End If

    ' *** Finished! ***

    End Sub

    2001 SAP AMERICA, INC. AND SAP AG