Calling a function module

Calling function modules in Rfc Connector is really easy, all it requires is just three steps:

  1. Connect to the SAP system in question
  2. Import the function module prototype and set parameter values
  3. 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

Note: The files below are for Visual Studio 2008. Click here to download samples for Visual Studio 2010 instead.

icon Client example for Visual Basic .NET RfcClient_VB.NET.zip | 24.47 kB | Date: 2011-11-22

A sample project for VB.NET which shows how call functions and how to use the TableReader component


icon Client example for C# RfcClient_CSharp.zip | 76.08 kB | Date: 2011-06-08

A sample project for C# which shows how call functions and how to use the TableReader component


icon Client example for Visual Basic 6 VB6GetFlights.zip | 9.46 kB | Date: 2011-06-08

A sample project for Visual Basic 6 which shows how call a function module and display the result in a form


icon Client example for C++ RfcClient_CPP.zip | 10.7 kB | Date: 2011-11-22

A sample client in plain (unmanaged) C++ with ATL