Professional Documents
Culture Documents
TABLE OF CONTENTS....................................................................................................................... 2
1 INTRODUCTION........................................................................................................................... 3
1.1 ORGANIZATION OF MATERIAL.................................................................................................. 3
1.2 REFERENCES........................................................................................................................ 3
2 CREATING WORKBOOK TEMPLATES IN EXCEL.....................................................................3
1.2 References
SAP BW Online Documentation
2. To save your work select the Save Save as new workbook on the BEx toolbar. In the dialog
box choose a folder and type in a name for your template.
You can open this workbook by choosing one of the following functions from the Settings menu from
the BEx toolbar.
With this function, you can determine into which workbook a query is embedded:
Select the function is selected from list if you want to choose beforehand, the workbook into
which you want to insert the query.
Select the function is based on permanent template if you want to insert the query into the
workbook that you have defined as a permanent workbook template. To do so, use the
function Permanent Workbook Template. You can then insert new queries into this kind of
permanent workbook template. If you select the function New workbook on embed Is
based on permanent template, then all queries are inserted automatically into a new
workbook that is based on the permanent workbook template.
The API (Application Programming Interface) offers us various VBA routines of the BEx add-in, with
which you can control the Business Explorer Analyzer functions. In our first example we will add
some coding behind the buttons we created in the previous section for a simple drilldown.
The Function SAPBEXsetDrillState changes the drilldown status. The Syntax of the statement is:
Function SAPBEXsetDrillState(newState As Integer, Optional atCell As Range) As Integer
newState = 0 means do not drilldown anymore
newState = 1 means drilldown vertically
newState = 2 means drilldown horizontally
The Cell refers to a filter cell from our navigation block within Excel.
Note the Cells for Distribution Channel (Row 10, Column 3), Material (Row 11, Column 3)
and Sold-to party (Row 13, Column 3).
2. Use the right mouse click on the first button and assign the following macro:
Sub Button1_Click()
Dim myState As Integer
Dim myFilterCell As Range: Set myFilterCell = ActiveSheet.Cells(10, 3)
Run "SAPBEX.XLA!SAPBEXgetDrillState", myState, myFilterCell
myState = Run("SAPBEX.XLA!SAPBEXgetDrillState_currentState")
If myState = 0 Then
Run "SAPBEX.XLA!SAPBEXsetDrillState", 1, myFilterCell
Else
Run "SAPBEX.XLA!SAPBEXsetDrillState", 0, myFilterCell
End If
End Sub
3. On the second and third button we add the same coding, but we change the reference in
ActiveSheet.Cells to the other Characteristics.
Sub Button2_Click()
Dim myState As Integer
Dim myFilterCell As Range: Set myFilterCell = ActiveSheet.Cells(11, 3)
Run "SAPBEX.XLA!SAPBEXgetDrillState", myState, myFilterCell
myState = Run("SAPBEX.XLA!SAPBEXgetDrillState_currentState")
If myState = 0 Then
Run "SAPBEX.XLA!SAPBEXsetDrillState", 1, myFilterCell
Else
Run "SAPBEX.XLA!SAPBEXsetDrillState", 0, myFilterCell
End If
End Sub
Sub Button3_Click()
Dim myState As Integer
4. By selecting a button with the right mouse key you can change the text of the button. Change
them into Distr. Channel", "Material and Sold-to party.
5. By clicking on the buttons the system will add and remove the drilldowns.
6. In the next step you can hide the navigational block using the Hide function from Excel and
navigate only via the buttons.
3. Now we can add a fourth button for a drillthrough to R/3. Therefore we have to define the
jump target.
Sub Button4_Click()
Run "SAPBEX.XLA!SAPBEXjump", "r", "QURY0001", Selection
End Sub
Please note here the two changes in the coding compared to our coding before. The jump
target is no longer a view ("v"), here we call an R/3 transaction ("r") and there is no Cell at
the end of the statement. The Cursorposition determines the value for the Cell.
In the next section we add two buttons for sorting the data. If you look at the available command set
in Chapter 4, you can find no special command for sorting. We can use the command
Function SAPBEXfireCommand(fCode As String, Optional atCell As Range) As Integer
for this purpose.
1. In the first step we have to find out the fCode for "sort in ascending order" and "sort in
descending order" Switch on the Trace function in the BEx toolbar.
SOAV is the fCode for Sort ascending and SODV is the fCode for descending
4. Add the following code to your buttons:
Sub Button5_Click()
Run "SAPBEX.XLA!SAPBEXfireCommand", "SOAV", Selection
End Sub
Sub Button6_Click()
Run "SAPBEX.XLA!SAPBEXfireCommand", "SODV", Selection
End Sub
You can use this technic also for other functions from the Bex toolbar.
Interactive charts are charts, which are directly combined with control elements. You can use them to
circumscribe the data view. For example, consider the query:
You can now create a chart and with a combo box that refers to all Materials.
1. Insert a chart and combo box
Select the first two rows and insert the chart.
Activate the Forms toolbar and insert a combo box. While selecting the control with the right
mouse button, give it the new name myDropDown.
To assign the combo box to the refreshed query, namely SAPBEXq0001, insert the following
code:
Sub SAPBEXonRefresh(queryID As String, resultArea as Range)
Dim myDrop As Shape
Dim myRange As Range
If queryID = "SAPBEXq0001" then
Set myDrop = Worksheets("Sheet1").Shapes("myDropDown")
myDrop.ControlFormat.ListFillRange = _
Range(resultArea.Columns(1).Cells(2).Address, _
resultArea.Columns(1).Cells(1).Offset( _
resultArea.Rows.Count-1,0).Address).Address
myDrop.ControlFormat.ListIndex = 1
End If
End Sub
This works now in perfect combination with our buttons. We first have a drilldown into materials:
As you can see the combo box now contains the Sold-to party values.