SAP-通过使用.NET连接器从使用.NET连接到SAP-错误调用SAP查询

发布于 2025-01-27 13:27:05 字数 2575 浏览 4 评论 0原文

我有以下代码,VB代码试图连接到SAP

获取以下错误:

'呼叫rfc_metadata_get'的目标FSD失败 'sap.middleware.connector.rfccommunication exception'sapnco.dll'

代码:

Private Shared Function Invoke(ByVal destination As RfcDestination, ByVal table As String, ByVal fields As List(Of SAPFieldItem), ByVal options As List(Of SAPFieldItem))

    Try


        '04052022
        Dim func As IRfcFunction = destination.Repository.CreateFunction("RFC_GET_CUST")  ' QUE_DOTNET__01   'RFC_GET_CUST

        'set fields
        If fields IsNot Nothing Then
            Dim fs As IRfcTable = func.GetTable("FIELDS")
            For i As Integer = 0 To fields.Count - 1
                fs.Append()
                fs.CurrentIndex = i
                fs.SetValue("FIELDNAME", fields(i).FieldId)
            Next
        End If

        'set options
        If options IsNot Nothing Then
            Dim opts As IRfcTable = func.GetTable("OPTIONS")
            For i As Integer = 0 To options.Count - 1
                opts.Append()
                opts.CurrentIndex = i
                opts.SetValue("TEXT", If(i > 0, " AND ", "") + options(i).makeWhere)
            Next
        End If

        func.SetValue("QUERY_TABLE", SAPFieldItem.escape(table))

        func.Invoke(destination)

        Dim result As New List(Of Dictionary(Of String, String))

        Dim index As Integer = 0
        Dim struct As IRfcTable = func.GetTable("FIELDS")
        Dim columns As New Dictionary(Of String, Integer)

        For i As Integer = 0 To struct.Count - 1
            struct.CurrentIndex = i
            columns.Add(struct.GetString("FIELDNAME"), struct.GetInt("LENGTH"))
        Next

        Dim data As IRfcTable = func.GetTable("DATA")
        For i As Long = 0 To data.Count - 1
            data.CurrentIndex = i
            Dim line = data.GetString("WA")

            Dim row As New Dictionary(Of String, String)
            Dim position As Integer = 0
            For Each c In columns
                If position + c.Value <= line.Length Then
                    row.Add(c.Key, line.Substring(position, c.Value).Trim)
                ElseIf position <= line.Length Then
                    row.Add(c.Key, line.Substring(position).Trim)
                Else
                    row.Add(c.Key, String.Empty)
                End If
                position += c.Value
            Next
            result.Add(row)
        Next

        Return result
    Catch ex As Exception
        Console.WriteLine(ex.Message)
    End Try
End Function

I have the below code , VB code trying to connect to SAP

getting the below error :

‘destination FSD failed when calling RFC_METADATA_GET’
‘Exception thrown: 'SAP.Middleware.Connector.RfcCommunicationException' in sapnco.dll’

Code:

Private Shared Function Invoke(ByVal destination As RfcDestination, ByVal table As String, ByVal fields As List(Of SAPFieldItem), ByVal options As List(Of SAPFieldItem))

    Try


        '04052022
        Dim func As IRfcFunction = destination.Repository.CreateFunction("RFC_GET_CUST")  ' QUE_DOTNET__01   'RFC_GET_CUST

        'set fields
        If fields IsNot Nothing Then
            Dim fs As IRfcTable = func.GetTable("FIELDS")
            For i As Integer = 0 To fields.Count - 1
                fs.Append()
                fs.CurrentIndex = i
                fs.SetValue("FIELDNAME", fields(i).FieldId)
            Next
        End If

        'set options
        If options IsNot Nothing Then
            Dim opts As IRfcTable = func.GetTable("OPTIONS")
            For i As Integer = 0 To options.Count - 1
                opts.Append()
                opts.CurrentIndex = i
                opts.SetValue("TEXT", If(i > 0, " AND ", "") + options(i).makeWhere)
            Next
        End If

        func.SetValue("QUERY_TABLE", SAPFieldItem.escape(table))

        func.Invoke(destination)

        Dim result As New List(Of Dictionary(Of String, String))

        Dim index As Integer = 0
        Dim struct As IRfcTable = func.GetTable("FIELDS")
        Dim columns As New Dictionary(Of String, Integer)

        For i As Integer = 0 To struct.Count - 1
            struct.CurrentIndex = i
            columns.Add(struct.GetString("FIELDNAME"), struct.GetInt("LENGTH"))
        Next

        Dim data As IRfcTable = func.GetTable("DATA")
        For i As Long = 0 To data.Count - 1
            data.CurrentIndex = i
            Dim line = data.GetString("WA")

            Dim row As New Dictionary(Of String, String)
            Dim position As Integer = 0
            For Each c In columns
                If position + c.Value <= line.Length Then
                    row.Add(c.Key, line.Substring(position, c.Value).Trim)
                ElseIf position <= line.Length Then
                    row.Add(c.Key, line.Substring(position).Trim)
                Else
                    row.Add(c.Key, String.Empty)
                End If
                position += c.Value
            Next
            result.Add(row)
        Next

        Return result
    Catch ex As Exception
        Console.WriteLine(ex.Message)
    End Try
End Function

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文