VB的代码,仅供参考,自己改改就能放到vb.net中
Dim functionCtrl As Object 'Function Control (Collective object)
Dim sapConnection As Object 'Connection object
Dim theFunc As Object 'Function object
Dim ls_material As String
'Create a function object
Set functionCtrl = CreateObject("SAP.Functions")
Set sapConnection = functionCtrl.Connection
If sapConnection.Logon(0, False) <> True Then
MsgBox "No connection to R/3!"
Exit Sub 'End program
End If
Dim i As Integer
i = 7
Do While Worksheets("Sheet1").Cells(i, 3) <> ""
ls_material = Sheet1.Cells(i, 3)
Set theFunc = functionCtrl.Add("ZRFC_GET_MAKTX")
theFunc.exports("MATNR") = ls_material
returnFunc = theFunc.Call
If returnFunc = True Then
Sheet1.Cells(i, 11) = theFunc.imports("MAKTX").Value
End If
i = i + 1
Loop
Sheet1.Cells(5, 11) = "图号"
functionCtrl.Connection.logoff
Set sapConnection = Nothing
Set functionCtrl = Nothing