我试图在SAP中获取此字段名称:
session.findById("wnd[0]/usr/subBLOCK:SAPLKACB:1015/ctxtCOBL-KOSTL")
我有以下代码,检查给定屏幕中的每个对象:
Option Explicit
Sub SAPfields()
Dim sapguiauto As Object
Dim sapapp As Object
Dim sapcon As Object
Dim session As Object
Dim Area As Object
Dim i As Long
Dim Children As Object
Dim Obj As Object
Set sapguiauto = GetObject("SAPGUI")
Set sapapp = sapguiauto.GetScriptingEngine
Set sapcon = sapapp.Children(0)
Set session = sapcon.Children(0)
Set Area = session.findById("wnd[0]/usr")
Set Children = Area.Children()
For i = 0 To Children.Count() - 1
Set Obj = Children(CInt(i))
Debug.Print Obj.Name
Next i
Set Children = Nothing
Set Obj = Nothing
End Sub
当我打印对象名称时,我得到了这个:
subBLOCK:SAPLKACB:1015
我该怎么做才能获得准确的字段?我试图使用OBJ("subBLOCK:SAPLKACB:1015").Children()
,但它不起作用。
答案 0 :(得分:0)
我会使用SAP GUI脚本记录器。然后你可以看到录制的剧本。
答案 1 :(得分:0)
在我的系统(SAP前端版本7400.3.13.3369)上,执行代码将为我提供字段名称,但它不是完全限定的。
例如这是我系统上SQVI屏幕上的选择标准。
在显示该屏幕的情况下运行您的过程,我得到以下信息:
%BS02000_BLOCK_1000 %_SP$00001_%_APP_%-TEXT SP$00001-LOW %_SP$00001_%_APP_%-TO_TEXT ...
您只需更改代码即可显示Obj.ID
,如下所示,以获取字段名称的完全限定路径。
...
debug.print Obj.ID
...
这给出了
/app/con[0]/ses[0]/wnd[0]/usr/box%BS02000_BLOCK_1000
/app/con[0]/ses[0]/wnd[0]/usr/txt%_SP$00001_%_APP_%-TEXT
/app/con[0]/ses[0]/wnd[0]/usr/ctxtSP$00001-LOW
/app/con[0]/ses[0]/wnd[0]/usr/txt%_SP$00001_%_APP_%-TO_TEXT
...
如果要在屏幕上显示文本,请使用.Text
:
...
debug.print "Name=" & Obj.Name & " Value=" & Obj.Text
...
Name=%_SP$00001_%_APP_%-TEXT Value=Plant
Name=SP$00001-LOW Value=
Name=%_SP$00001_%_APP_%-TO_TEXT Value=to
Name=SP$00001-HIGH Value=
Name=%_SP$00001_%_APP_%-VALU_PUSH Value=
...
仅供参考,如ScriptMan建议的那样,要获取当前具有焦点的数据元素的字段名称,您可以使用以下脚本。
Sub GetSAPObjectID()
'-Variables---------------------------------------------------------
Dim SAPGUI
Dim App
Dim Con
Dim Ses
Dim ActID
Set SAPGUI = GetObject("SAPGUI")
If Not IsObject(SAPGUI) Then
Exit Sub
End If
Set App = SAPGUI.GetScriptingEngine()
If Not IsObject(App) Then
SAPGUI = Nothing
Exit Sub
End If
Set Con = App.Children(0)
If Not IsObject(Con) Then
Set App = Nothing
Set SAPGUI = Nothing
Exit Sub
End If
Set Ses = Con.Sessions(0)
If Not IsObject(Ses) Then
Set Con = Nothing
Set App = Nothing
Set SAPGUI = Nothing
Exit Sub
End If
ActID = Ses.ActiveWindow.SystemFocus.ID
Debug.Print ActID
Set Ses = Nothing
Set Con = Nothing
Set App = Nothing
Set SAPGUI = Nothing
End Sub