|
SAP提供了自己的API给做自动化的测试员用,所以不一定要使用QTP的插件。只是自己开发费用比较高。还有维护。
SAP提供了包括VBA,VBS,JAVA,.NET等等的接口。
Function CallSAPFUNC()
Dim oConnection As Object
Dim ofun As Object
Dim func As Object
Set ofun = CreateObject("SAP.FUNCTIONS") ' FUNCTION NAME
Set ofun.Connection = oConnection
Set func = ofun.Add("RFC_READ_TABLE")
func.Exports("QUERY_TABLE") = "CSKT" ' TABLE NAME
If func.Call = True Then
Set oline = func.Tables.Item("DATA")
Row = oline.RowCount
Sheet2.Cells(1, 1) = "0000"
Sheet2.Cells(1, 2) = "??"
Sheet2.Cells(1, 3) = "????"
Sheet2.Cells(1, 4) = "?"
Sheet2.Cells(1, 5) = "?????"
Sheet2.Cells(1, 6) = "????"
Sheet2.Cells(1, 7) = "0"
Sheet2.Cells(1, 8) = "??"
i = 2
Do While i <= 100
Sheet2.Cells(i, 1) = Mid(Trim(oline.Value(i, 1)), 1, 3)
Sheet2.Cells(i, 2) = Mid(Trim(oline.Value(i, 1)), 4, 1)
Sheet2.Cells(i, 3) = Mid(Trim(oline.Value(i, 1)), 5, 4)
Sheet2.Cells(i, 4) = Mid(Trim(oline.Value(i, 1)), 9, 10)
Sheet2.Cells(i, 5) = Mid(Trim(oline.Value(i, 1)), 19, 8)
Sheet2.Cells(i, 6) = Mid(Trim(oline.Value(i, 1)), 27, 20)
Sheet2.Cells(i, 7) = Mid(Trim(oline.Value(i, 1)), 47, 40)
Sheet2.Cells(i, 8) = Mid(Trim(oline.Value(i, 1)), 87, 26)
i = i + 1
Loop
End If
ll = MsgBox("END PROCESS", , "END")
End Function
如何创建OBJECT
Set ctlLogon = CreateObject("SAP.LogonControl.1")
Set funcControl = CreateObject("SAP.Functions")
Set ctlTableFactory = CreateObject("SAP.TableFactory.1")
Set objSession = CreateObject("MAPI.Session")
你可以使用这些东西去获取已经打开的SAP 程序,然后开始对它做操作。
如何获取SAP 数据
Dim SapGuiAuto
Dim application
Dim connection
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
Set connection = application.Children(0)
Set session = connection.Children(0)
Set ofun = CreateObject("SAP.FUNCTIONS") '
Set ofun.Connection = connection
Set func = ofun.Add("RFC_READ_TABLE")
func.Exports("QUERY_TABLE") = "CSKT"
If func.call=true Then
Set oline = func.Tables.Item("Data")
msgbox oline.RowCount
msgbox oline.value(1,1)
End If
这些东西因为之前项目正好在做SAP,我比较不安分,研究了点点东西,和你share这些,希望对你有帮助。这些代码比较原汁原味,你在里面提取对你有用的信息吧。如果你想了解更多...::yxiao:::
顺便提及一下,如果你想让你们头头觉得你是牛人,你就把代码写成宏,然后自己加密,或者自己做DLL~~加密...哈哈,让他们饮水思源。::yiwusuoyou::: |
|