SAP-通过使用.NET连接器从使用.NET连接到SAP-错误调用SAP查询
我有以下代码,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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论