本文主要是介绍SAP接口编程-RFC系列10 : BAPI控件的DimAs方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
BAPI控件的DimAs方法
上一个示例中,input parameter都是单值的。如果input parameter是结构型或table型的,就需要使用bapiControl.DimAs()方法定义,否则出错。以Customer.GetList()方法为例(对应的FM: BAPI_CUSTOMER_GETLIST)
以下是代码,注意IdRange参数是一个range table,所以用DimAs方法来定义。
Option ExplicitPublic Sub TestGetCustomerList()Call LogonCall DoGetCustomerList("0", "ZZZZ", "100")Call logoff
End SubPublic Sub DoGetCustomerList(customerFrom As String, customerTo As String, maxRow As String)Dim bapiControl As SAPBAPIControlLib.SAPBAPIControlDim customerObj As ObjectDim customerRng As SAPTableFactoryCtrl.Table ' IdRange parameterDim address As SAPTableFactoryCtrl.TableDim ret As SAPFunctionsOCX.StructureIf sapConnection.IsConnected <> tloRfcConnected ThenDebug.Print "Please connect to SAP first."Exit SubEnd IfSet bapiControl = New SAPBAPIControlSet bapiControl.Connection = sapConnectionSet customerObj = bapiControl.GetSAPObject("Customer")' fill IdRange parameterSet customerRng = bapiControl.DimAs(customerObj, "GetList", "IdRange")customerRng.AppendRowcustomerRng.Value(1, "SIGN") = "I"customerRng.Value(1, "OPTION") = "BT"customerRng.Value(1, "LOW") = customerFromcustomerRng.Value(1, "HIGH") = customerToIf maxRow = "" ThencustomerObj.GetList IdRange:=customerRng, _AddressData:=address, _Return:=retElsecustomerObj.GetList IdRange:=customerRng, _AddressData:=address, _MaxRows:=maxRow, _Return:=retEnd If' Error occuredIf ret("TYPE") = "E" ThenCall DebugWriteBapiError(ret)Exit SubEnd IfIf address.rowcount > 0 ThenDim sht As WorksheetSet sht = ThisWorkbook.Worksheets.AddCall WriteTable(address, sht)End IfSet address = NothingSet customerObj = NothingSet bapiControl = Nothing
End SubPrivate Sub DebugWriteBapiError(error As SAPFunctionsOCX.Structure)Debug.Print "Type:", error.Value("TYPE")Debug.Print "Class:", error.Value("ID")Debug.Print "Number:", error.Value("NUMBER")Debug.Print "Message:", error.Value("MESSAGE")
End Sub
DimAs 语法:
Function DimAs(Object As Object, Method As String, Parameter As String) As Object
这篇关于SAP接口编程-RFC系列10 : BAPI控件的DimAs方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!