‎2008 Mar 11 7:37 AM
Hi Friends,
My requirement is that i need to developer application in VB and retrieve data from SAP i thing its only possible through RFC
so pls tell me what are the basic steps i need to follow to call RFC from SAP To VB
in VB my input will be material number and i need to fetch data from SAP for that material.....
i anybody have sample code than pls share it
‎2008 Mar 11 7:51 AM
Hello.
You may use a BAPI calling via RFC.
-
Function SetupConnection() As Boolean
'Make connection to SAP SYSTEM
Set oLogonCtrl = CreateObject("SAP.Logoncontrol.1")
Set oBAPICtrl = CreateObject("SAP.BAPI.1")
Set oBAPICtrl.Connection = oLogonCtrl.NewConnection
' Try to connect
If oBAPICtrl.Connection.Logon = False Then
MsgBox "Connection Failed"
SetupConnection = False
Else
SetupConnection = True
End If
End Function
And you may call a BAPI Method
In my case, BAPI retriev all creditor number from R/3 system
-
Sub LoadNumber(TBLNAME As String)
Dim KONTR As Object
Dim NUMBER As Object
Dim NUMTBL As Object
Dim i As Long
' make connection to R/3
If SetupConnection Then
' Calling BAPI
Set KONTR = oBAPICtrl.GetSAPObject("ZIFI_LFA1")
' Make variable for BAPI Export parameter
Set NUMBER = oBAPICtrl.DimAs(KONTR, "Vendor_Get_Number", "Number")
' Calling BAPI method
KONTR.Vendor_Get_Number _
NUMBER:=NUMBER
If NUMBER.RowCount < 1 Then
MsgBox "No creditor in system"
Else
' Open table
Set NUMTBL = CurrentDb.OpenRecordset(TBLNAME)
DeleteAll NUMTBL
' transfer data from R/3 to database table
For i = 1 To NUMBER.RowCount
NUMTBL.AddNew
NUMTBL!Lifnr = NUMBER.Value(i, "LIFNR")
NUMTBL!Sortl = NUMBER.Value(i, "SORTL")
NUMTBL.Update
Next i
End If
MsgBox "transfer complete"
Else
MsgBox "Failed connect to R/3"
End If
End Sub
Edited by: Pavel Martinov on Mar 11, 2008 10:54 AM