Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

RFC From VB

Former Member
0 Likes
399

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

1 REPLY 1
Read only

Former Member
0 Likes
349

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