Simple Example

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. Define the fields of the function module to be called (and assign values to the importing parameters)
  3. Call the function
Note: While this example is written in VBA, you can use Rfc Connector with every language supporting COM, including C/C++/C#, VB 6, VB.net and Delphi).
 ' 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

 ' define the function module's signature
 Dim sBAPISFLDAT As RfcType, fn As FunctionCall
 Set fn = Session.CreateCall  
 fn.Function = "BAPI_FLIGHT_GETLIST"
 
 ' Rfc Connector allows to import structure definitions on the fly
 Set sBAPISFLDAT = Session.ImportType("BAPISFLDAT")
   
 ' this function module has IMPORTING and TABLES parameter
 fn.importing.AddScalar "AIRLINE", TYPE_CHAR, 3, , "LH"
 fn.tables.AddTable "FLIGHT_LIST", sBAPISFLDAT
 
 ' call the function 
 Session.CallFunction fn

Retrieving SAP Data with Excel

ScreenshotIf you have read the example above carefully, you'll eventually feel the urge to complain that there is actually no processing of the retrieved data. Just stay tuned, in the following example we're going to show you how to turn these code into a full blown, Excel based "flight information system", using SAP's example SFLIGHT data model. You can click the image on the left to see a larger version).

Using SAP tables is pretty straightforward with Rfc Connector:
 ' since tables are COM collections, they can be enumerated 
 ' with the For Each construct
 rowNo = 10
 For Each row In fn.tables("FLIGHT_LIST").Rows
    Tabelle1.Cells(rowNo, 2) = row("AIRLINEID")
    Tabelle1.Cells(rowNo, 3) = row("CONNECTID")
    Tabelle1.Cells(rowNo, 4) = row("AIRPORTFR")
    Tabelle1.Cells(rowNo, 5) = row("AIRPORTTO")
    Tabelle1.Cells(rowNo, 6) = row("FLIGHTDATE")
    Tabelle1.Cells(rowNo, 7) = row("DEPTIME")
    Tabelle1.Cells(rowNo, 8) = row("ARRTIME")
    rowNo = rowNo + 1
 Next
Click here to view the complete source code

Calling Web Applications

ScreenshotWhen deploying web-based applications to end users, developers typically have to cope with the following limitations:
  • users navigating away by closing the browser, using the back button or entering something into the address bar
  • additional login forms where users must enter their username and password, even if they are already logged on to the back-end
  • no way to close the browser window programmatically without an additional popup
  • no easy method of returning values from the web service to the calling applications

The built-in web application support of Rfc Connector solves all this, and it is easy to use:
 ' Define server address, user and password for the web application
 Dim bsp As New BSPApplication
   
 bsp.HttpSystemData.Host = "myhost"
 bsp.HttpSystemData.Port = "myport"

 bsp.LogonData.Client = "000"
 bsp.LogonData.User = "myuser"
 bsp.LogonData.Password = "mypassword"
 bsp.LogonData.Language = "en"
 
 ' define the window properties (size, position and title)
 bsp.Window.Left = 100
 bsp.Window.Top = 100
 bsp.Window.Height = 800
 bsp.Window.Width = 600
 bsp.Window.Title = "My BSP Window"
  

 ' display a warning when user is about to close the window
 bsp.Window.CloseWarning = "Do you really want to close \
                                 this window?" & vbCrLf \
                                  & "Data loss may occur"

 ' call the application
 bsp.ShowApplication "/sap/bc/bsp/zwebapp/default.htm", exitPage