BW--API functions available in BEX 3.x

本文详细介绍了BEx3.X可用的API函数及其应用场景,包括连接BW服务器、设置过滤器值、刷新查询等操作,并提供了函数调用的示例代码。

一、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-589141/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15232446/viewspace-589141/

源码来自:https://pan.quark.cn/s/7a757c0c80ca 《在Neovim中运用Lua的详尽教程》在当代文本编辑器领域,Neovim凭借其卓越的性能、可扩展性以及高度可定制的特点,赢得了程序开发者的广泛青睐。 其中,Lua语言的融入更是为Neovim注入了强大的活力。 本指南将深入剖析如何在Neovim中高效地运用Lua进行配置和插件开发,助你充分发挥这一先进功能的潜力。 一、Lua为何成为Neovim的优选方案经典的Vim脚本语言(Vimscript)虽然功能完备,但其语法结构与现代化编程语言相比显得较为复杂。 与此形成对比的是,Lua是一种精简、轻量且性能卓越的脚本语言,具备易于掌握、易于集成的特点。 因此,Neovim选择Lua作为其核心扩展语言,使得配置和插件开发过程变得更加直观和便捷。 二、安装与设置在Neovim中启用Lua支持通常十分简便,因为Lua是Neovim的固有组件。 然而,为了获得最佳体验,我们建议升级至Neovim的最新版本。 可以通过`vim-plug`或`dein.vim`等包管理工具来安装和管理Lua插件。 三、Lua基础在着手编写Neovim的Lua配置之前,需要对Lua语言的基础语法有所掌握。 Lua支持变量、函数、控制流、表(类似于数组和键值对映射)等核心概念。 它的语法设计简洁明了,便于理解和应用。 例如,定义一个变量并赋值:```lualocal myVariable = "Hello, Neovim!"```四、Lua在Neovim中的实际应用1. 配置文件:Neovim的初始化文件`.vimrc`能够完全采用Lua语言编写,只需在文件首部声明`set runtimepath^=~/.config/nvim ini...
基于STM32 F4的永磁同步电机无位置传感器控制策略研究内容概要:本文围绕基于STM32 F4的永磁同步电机(PMSM)无位置传感器控制策略展开研究,重点探讨在不使用机械式位置传感器的情况下,如何通过算法实现对电机转子位置和速度的精确估算与控制。文中结合STM32 F4高性能微控制器平台,采用如滑模观测器(SMO)、扩展卡尔曼滤波(EKF)或高频注入法等先进观测技术,实现对电机反电动势或磁链的实时估算,进而完成磁场定向控制(FOC)。研究涵盖了控制算法设计、系统建模、仿真验证(可能使用Simulink)以及在嵌入式平台上的代码实现与实验测试,旨在提高电机驱动系统的可靠性、降低成本并增强环境适应性。; 适合人群:具备一定电机控制理论基础和嵌入式开发经验的电气工程、自动化及相关专业的研究生、科研人员及从事电机驱动开发的工程师;熟悉C语言和MATLAB/Simulink工具者更佳。; 使用场景及目标:①为永磁同步电机驱动系统在高端制造、新能源汽车、家用电器等领域提供无位置传感器解决方案的设计参考;②指导开发者在STM32平台上实现高性能FOC控制算法,掌握位置观测器的设计与调试方法;③推动电机控制技术向低成本、高可靠方向发展。; 其他说明:该研究强调理论与实践结合,不仅包含算法仿真,还涉及实际硬件平台的部署与测试,建议读者在学习过程中配合使用STM32开发板和PMSM电机进行实操验证,以深入理解控制策略的动态响应与鲁棒性问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值