Calling a function module
Calling function modules in Rfc Connector is really easy, all it requires is just three steps:
- Connect to the SAP system in question
- Import the function module prototype and set parameter values
- Call the function
Note: While this example is written in Visual Basic, you can use Rfc Connector with every language which supports COM, including C/C++/C#, VBA, VB 6, VB.net, Delphi, Auto IT and many more.
' connect to SAP system via RFC
Session.RfcSystemData.ConnectString = "ASHOST=myserver SYSNR=00"
Session.LogonData.Client = "000"
Session.LogonData.User = "myuser"
Session.LogonData.Password = "supersecret"
Session.LogonData.Language = "EN"
Session.Connect()
' import function module's prototype
Dim fn As FunctionCall
fn = Session.ImportCall("BAPI_FLIGHT_GETLIST")
' set importing parameters
fn.Importing("AIRLINE").value = "LH"
' call the function
Session.CallFunction(fn)
' process the result
For Each row As RfcFields In fn.Tables("FLIGHT_LIST").Rows
Console.WriteLine(Row("AIRLINE").value & " " & Row("FLIGHTDATE").value)
Next
Retrieving SAP Table Data
With Rfc Connector‘s integrated TableReader class, you can retrieve data from SAP tables with just a few lines of code:
Dim tr As TableReader
tr = session.GetTableReader("SFLIGHT")
' set a query condition
tr.Query.Add("CARRID EQ 'LH'")
' read the table
tr.Read(0,0)
' process the result
For Each row As RfcFields in tr.Rows
Console.WriteLine(row("FLDATE").value & " " & row("CONNID").value)
' ...
Next
Sample Projects
The sample projects are now hosted at GitHub:
