ITPub博客

首页 > Linux操作系统 > Linux操作系统 > BW--API functions available in BEX 3.xBEx 3.X可用API函数列表和使用样

BW--API functions available in BEX 3.xBEx 3.X可用API函数列表和使用样

原创 Linux操作系统 作者:vcdone 时间:2008-09-06 21:26:00 0 删除 编辑

一、BEx 3.X可用API函数列表

1. Function SAPBEXinitConnection(Optional newConnectionObj As Object) As Boolean
Set up a connection to BW Server

2. Function SAPBEXgetConnection(Optional what As Integer) As Variant
Get the existing connection object if already connected to BW server by help of BEX

3. Sub SAPBEXattachGIS(Optional refreshOnly As Boolean)
Attach GIS-MAP (same as clicking the BEX-Toolbar button)

4. Sub SAPBEXpauseOn()
In case you like to fire more than one API command (like two individual filter values) without immediate refresh

5. Sub SAPBEXpauseOff()
After this command all of the commands called after SAPBEXpauseOn will be executed

6. Function SAPBEXsetVariables(varValues As Range) As Integer
Set variable Values for User to provide Pop-Up Filter selections (Filter dialogs will be disabled if properly filled)

7. Function SAPBEXrefresh(allQueries As Boolean, Optional atCell As Range) As Integer
Refresh either all Queries in Workbook allQueries=FALSE or selected Queries by identifying the Query range

8. Function SAPBEXsetDrillState(newState As Integer, Optional atCell As Range) As Integer

Set the Drill state via coding to: vertical (newState=1) or horizontal (newState=2) or no drill state (newState=0)

9. Function SAPBEXgetDrillState(currentState As Integer, Optional atCell As Range) As Integer
Find out what DrillState is defined for a specific object

10. Function SAPBEXsetFilterValue(intValue As String, Optional hierValue As String, Optional atCell As Range) As Integer
Set a filter value for a specific characterictic ( i.E. 0CUSTOMER = 1002) to filter either on simple or hierarchy values.

11. Function SAPBEXgetFilterValue(intValue As String, hierValue As String, Optional atCell As Range) As Integer
Get a filter value for a specific characterictic ( i.E. 0CUSTOMER) to use it later on either on simple or hierarchy node.

12. Function SAPBEXcopyFilterValue(fromCell As Range, Optional atCell As Range) As Integer
Copy a filter value for a specific characteristic see our little example above

13. Function SAPBEXfireCommand(fCode As String, Optional atCell As Range) As Integer
Fire commands like remote control context menu or toolbar (values can be found via Trace file)

14. Function SAPBEXcheckContext(fCode As String, Optional atCell As Range) As Integer
Check if an OLAP command like SAPBEXfireCommand can be used on that particular cell

15. Function SAPBEXshowTextElements(Optional selectGroup As String, Optional atCell As Range) As Integer
Like display of text elements (filters, global values) via Toolbar

16. Function SAPBEXjump(jumpType As String, jumpTarget As String, Optional atCell As Range) As Integer
ReportReport Interface(RRI) ; Jump to a specified Workbook or view

17. Function SAPBEXgetResultRangeByID(ByVal queryID As String, Optional ByVal charName As String) As Range
Find out where data from query is being displayed; for example in case you like to add data to last column

18. Function SAPBEXsaveWorkbook(Optional wbName As String) As Integer
Save your workbook after refresh (no name needed) or save as new file

19. Function SAPBEXreadWorkbook(wbID As String) As String
Open your workbook via Workbook ID (GUID) see text above for later use

20. Function SAPBEXgetWorkbookID(wbName As String) As String
Find out workbook Id by open Workbook by 'human friendly' name. Return value is GUID

21. Function SAPBEXembedQuery(genUID As String, Optional atActiveCell As Boolean) As String
Like Toolbar function; embed a new query (not workbook) to your active workbook.

二、函数调用样例(Functions to Automate and Enhance Your BW Reports in Excel)

The following examples illustrate some of the functionality supported by the BEx API. See March 2004 BW Expert (page 10) for the complete list of functions and their corresponding numbers. Note that this is a partial list of the functions and some of the code offered below is used to combine features and build new functionality.

Functions 1 and 2 can be combined along with the following code to establish a connection with the server:

Public Function  LogonToYourBW()
' create Logon & RFC-Handle
 logonToBW = False ‘ clear connect Flag the flag can be used to find out if connected or not
    'load SAP functionality by opening BEX file ( use your installation path)
        Workbooks.Open (“c:\sappc\bw\sapbex.xla”)
    With Run("sapbex.xla!sapbexGetConnection") ‘ call the connection
       ' Set the params for Auto logon
       .client = “YOUR CLIENT NO”
       .user = “YOUR BW USER”
       .Password = “YOUR BW PWD” ‘ I recommend to create a dummy reporting user for this task
       .Language = “YOUR LANGUAGE YOU LIKE TO USE FOR QUERY DISPLAY ( i.E.  “EN”)”
       .SystemNumber = “YOUR SYSTEM NO” ‘
       .ApplicationServer = “YOUR SERVER Name OR IP-ADDRESS”
       .UseSAPLOgonIni = FALSE 'important for automatic connection
       .logon 0, True ‘ This will provide a dialog to appear
        If .IsConnected <> 1 Then
            .logon 0, False
            If .IsConnected <> 1 Then Exit Function
        Else
            Set g_oFunction = CreateObject("SAP.Functions")
            Set g_oFunction.Connection = g_oConnection
        End If
    End With
    Run "sapbex.xla!sapbexinitConnection" ‘ this will enable the connection you just created
    logonToBW = True
End Function

Function 7 can be used to refresh queries in an active workbook. To refresh all queries, set the first parameter to True and use the following code:

If Run("sapbex.xla!SAPBEXrefresh", True) = 0 Then
Else
    MsgBox " Error in Refresh"

To refresh a single query, reference a valid cell in the query (navigation or filter area or result area)

‘Set the values for Variables  
Dim rngVar as Range
Set rngVar = YOUR_VARIABLE_SHEET.Range(“A2:H3”)
Run "SAPBEXsetVariables", rngVar
If Run("SAPBEX.xla!SAPBEXrefresh", False, ActiveSheet.Range("C7")) = 0 Then
Else
    MsgBox "Error in Refresh”
End If

Function 8 and 9 allow you to change the drill down status in a report, either across or down, to hide certain areas while providing some basic functionality to users. The code below is to create a button for users to drill down or across (horizontal or vertical).  Note the following values for myDrillState:
myDrillState = 0  No drilldown”
myDrillState = 1  Drilldown is vertical
myDrillState = 2  Drilldown is horizontal

Coding for user button:

Sub btn_Customer_Click()
    Dim myDrillState As Integer
    Dim myFilterCell As Range
    ‘Set your filter cell
    Set myFilterCell = ActiveSheet.Range(“C13”)
    ‘Now get the actual status

 If Run( "SAPBEX.XLA!SAPBEXgetDrillState", myDrillState, myFilterCell) = 0 then
    myState = Run("SAPBEX.XLA!SAPBEXgetDrillState_currentState")
  ‘ Depending on found ststus set the opposite ( toggle) state
    If myState = 0 Then
        If Run( "SAPBEX.XLA!SAPBEXsetDrillState", 1, myFilterCell) = 0 Then
        Else
MsgBox “Error in Drill”
        End If
    Else
        If Run ("SAPBEX.XLA!SAPBEXsetDrillState", 0, myFilterCell) = 0 Then
        Else
 MsgBox “Error in Drill”
        End If
    End If
 End If
End Sub

Function 12 allows more complex commands to be executed than those available from the context menu. The code below sorts first by text ( SOAT) , then by characteristic by key (SOAK). To set the code up, first search your trace file for the OLAP function:
XLA:   13:31:28 calling OLAP function 
XLA:    - function code: SOAT 
XLA:    - array: Sheet1!$C$30:$EI$87 
XLA:    - Called AllowSetForegroundWindow, Result: True(<>0 is good) 
... 
... 
XLA:   13:32:20 calling OLAP function 
XLA:    - function code: SOAK 

Use the OLAP references to drill by a specific hierarchy level (HX03), in the case Level 3 (HX06 would be Hierarchy eXpand Level 06):

Function SetBexCommand()
'Function to change the hierarchy Drill Level as Example
Dim strCommand As String
Dim myCell As Range

strCommand = "HX03"
‘ Can be any valid ( Navigation Area or Data Area Range)
‘ I am setting the command to my customer in cel D11
Set myCell = Range(“D11”)
If Run("sapbex.xla!SAPBEXfireCommand", strCommand, ActiveSheet.Range(strMyCell)) = 0 Then
Else
 MsgBox “Error in Hierarchy Command”
End If
End Function

Function 14 validates a function in a particular cell (Note: It is recommend that you use this function before the SAPBEXfireCommand to avoid errors in your code)

Function SetBexCommand()
Dim strCommand As String
Dim myCell As Range
strCommand = "HX03"
Set myCell = Range(“D11”)
If Run("sapbex.xla!SAPBEXCheckCommand", strCommand, ActiveSheet.Range(strMyCell)) = 0 Then
If Run("sapbex.xla!SAPBEXFireCommand", strCommand, ActiveSheet.Range(strMyCell)) = 0 Then
Else
 MsgBox “Error in Hierarchy Command”
End If
End If
End Function

Function 15 turns on text information not implemented in an active workbook.

The following values can be used:
selectGroup = blank or "*": Show all text elements
selectGroup = "C": Show only general text elements (created by, changed on,...)
selectGroup = "F": Show filter only
selectGroup = "V": Show variables only

This example uses selectGroup = "C" to insert data into a footer in Excel

Function Get_text_Elem()
Dim selectGroup As String
Dim myRange As Range
    selectGroup = "C"
    Set myRange = ActiveSheet.Range("C23")
    If Run("SAPBEXshowTextElements", selectGroup) = 0 Then
    Else
        MsgBox "Error in Textelements"
    End If
End Function

Function 16 provides access to the Report Report Interface (RRI) to jump directly to another query.

View as Jump target

Private Sub CommandButton1_Click()
    If Run("SAPBEX.XLA!SAPBEXjump", "v", "My jump view", ActiveSheet.Range("D19")) = 0 Then
    Else
         MsgBox "ERROR in Jump Target"
    End If
End Sub

Query Jump target via RSBBS

Private Sub CommandButton1_Click()
    If Run("SAPBEX.XLA!SAPBEXjump", "r", "QURY0001", ActiveSheet.Range("D19")) = 0 Then
    Else
         MsgBox "ERROR in Jump Target"
    End If
End Sub

Function 18 automatically saves your workbooks.

Private Sub CommandButton1_Click()
    If Run("SAPBEX.XLA!SAPBEXsaveWorkbook") = 0 Then
    Else
         MsgBox "ERROR WB save"
    End If
End Sub

Function 19 opens workbooks without the BEx toolbar.

Private Sub CommandButton1_Click()
Dim strWBID As String
Dim strTmp As String

strWBID = "2A024RULBDK33U5BNZH60433U"
strTmp = Run("SAPBEX.XLA!SAPBEXreadWorkbook", strWBID)
    If strTmp = "" Then
         MsgBox "ERROR WB Read"
    End If
End Sub

Function 20 translates the human friendly name to the GUID being stored on the BW server.

Private Sub CommandButton1_Click()
Dim strWBName As String
Dim strWBID As String
strWBName = "Testquery Jump"

strWBID = "2A024RULBDK33U5BNZH60433U"
strWBID = Run("SAPBEX.XLA!SAPBEXreadWorkbook", strWBName)
    If strWBID = "" Then
         MsgBox "ERROR get WBID"
    End If
End Sub

Function 21 can be used to dynamically insert queries into an Excel workbook. There are two ways of using the function:
1. Boolean Value TRUE for the second parameter of that function, which will insert the query where you defined the active cell.
2. Leave the second function value blank, which open a new Workbook for a particular query.

Private Sub CommandButton1_Click()
Dim strQueryID As String
Dim strTmp As String

strQueryID = "85RFOO9I0FXTZOK5GP6X2UVNA"
ActiveWorkbook.Sheets("Sheet1").Range("A10").Select

strTmp = Run("SAPBEX.XLA!SAPBEXEmbedQuery", strQueryID)
    If strTmp = "" Then
         MsgBox "ERROR Insert Query"
    End If
End Sub

Combine Functions 4, 5, and 10 to create multiple function calls. Function 3, 4, and 10 can be combined to first stop the automatism in BEX, then collect all function calls, and execute the functions in batch:

Run "sapbex.xla!SAPBEXpauseOn()" ‘This will stop all automatic refreshes  by  SAP
‘Set the values for Variable 1  
If Run("SAPBEX.xla! SAPBEXSetFilterValue",YOUR_1_VARIABLE_VALUE,””, Sheets("Query_A").Range("B7")) = 0 Then
    Else
     MsgBox "Function failed"
    End If
‘Set the values for Variable 2
If Run("SAPBEX.xla! SAPBEXSetFilterValue",YOUR_2_VARIABLE_VALUE,””, Sheets("Query_A").Range("B5")) = 0 Then
    Else
     MsgBox "Function failed"
    End If
Run "sapbex.xla!SAPBEXpauseOn()"‘This will turn on all automatic refreshes  by  SAP and execute all functions since PauseOn

 

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15232446/viewspace-586617/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-08-19

  • 博文量
    62
  • 访问量
    107079