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