SAP接口编程-RFC系列10 : BAPI控件的DimAs方法

来源:互联网 发布:java的compare方法 编辑:程序博客网 时间:2024/04/30 10:27

BAPI控件的DimAs方法

上一个示例中,input parameter都是单值的。如果input parameter是结构型或table型的,就需要使用bapiControl.DimAs()方法定义,否则出错。以Customer.GetList()方法为例(对应的FM: BAPI_CUSTOMER_GETLIST)

这里写图片描述

这里写图片描述

以下是代码,注意IdRange参数是一个range table,所以用DimAs方法来定义。

Option ExplicitPublic Sub TestGetCustomerList()    Call Logon    Call DoGetCustomerList("0", "ZZZZ", "100")    Call logoffEnd SubPublic Sub DoGetCustomerList(customerFrom As String, customerTo As String, maxRow As String)    Dim bapiControl As SAPBAPIControlLib.SAPBAPIControl    Dim customerObj As Object    Dim customerRng As SAPTableFactoryCtrl.Table  ' IdRange parameter    Dim address As SAPTableFactoryCtrl.Table    Dim ret As SAPFunctionsOCX.Structure    If sapConnection.IsConnected <> tloRfcConnected Then        Debug.Print "Please connect to SAP first."        Exit Sub    End If    Set bapiControl = New SAPBAPIControl    Set bapiControl.Connection = sapConnection    Set customerObj = bapiControl.GetSAPObject("Customer")    ' fill IdRange parameter    Set customerRng = bapiControl.DimAs(customerObj, "GetList", "IdRange")    customerRng.AppendRow    customerRng.Value(1, "SIGN") = "I"    customerRng.Value(1, "OPTION") = "BT"    customerRng.Value(1, "LOW") = customerFrom    customerRng.Value(1, "HIGH") = customerTo    If maxRow = "" Then        customerObj.GetList IdRange:=customerRng, _            AddressData:=address, _            Return:=ret    Else        customerObj.GetList IdRange:=customerRng, _            AddressData:=address, _            MaxRows:=maxRow, _            Return:=ret    End If    ' Error occured    If ret("TYPE") = "E" Then        Call DebugWriteBapiError(ret)        Exit Sub    End If    If address.rowcount > 0 Then        Dim sht As Worksheet        Set sht = ThisWorkbook.Worksheets.Add        Call WriteTable(address, sht)    End If    Set address = Nothing    Set customerObj = Nothing    Set bapiControl = NothingEnd 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

0 0