Option Explicit
Private Sub CommandButton1_Click()
 Dim Session As New RfcSession
 
 On Error GoTo err:
 
 
 Session.RfcSystemData.ConnectString = "ASHOST=" & Tabelle1.Cells(4, 7) & " SYSNR=" & Tabelle1.Cells(5, 7)
 
 Session.LogonData.Client = Tabelle1.Cells(4, 9)
 Session.LogonData.User = Tabelle1.Cells(5, 9)
 Session.LogonData.Password = Tabelle1.Cells(6, 9)
 Session.LogonData.Language = Tabelle1.Cells(7, 9)
 
 Tabelle1.Range("B10", "H99").ClearContents
 
 Session.Option("trace.file") = "c:\rfc.trace"
 
 Session.Connect
 
 GetFlights Session, Tabelle1.Cells(4, 3), Tabelle1.Cells(5, 3), Tabelle1.Cells(6, 3)
 
 Session.Disconnect
 
 Exit Sub
 
err:
 MsgBox Error & vbCrLf & Session.ErrorInfo.Message
   
End Sub


Public Sub GetFlights(Session As ISession, Carrid As String, Cityfrom As String, cityto As String)
    
 Dim sBAPISFLDST As RfcType, sBAPISFLDAT As RfcType
 Dim fn As FunctionCall, row As RfcFields
 Dim rowNo As Integer
 
 Set sBAPISFLDST = Session.ImportType("BAPISFLDST")
 Set sBAPISFLDAT = Session.ImportType("BAPISFLDAT")
  
 Set fn = Session.CreateCall
 fn.Function = "BAPI_FLIGHT_GETLIST"
 fn.importing.AddScalar "AIRLINE", TYPE_CHAR, 3, , Carrid
 fn.importing.AddParameter "DESTINATION_FROM", sBAPISFLDST
 fn.importing("DESTINATION_FROM").Fields("AIRPORTID") = Cityfrom
 fn.importing.AddParameter "DESTINATION_TO", sBAPISFLDST
 fn.importing("DESTINATION_TO").Fields("AIRPORTID") = cityto
 
 fn.tables.AddTable "FLIGHT_LIST", sBAPISFLDAT
 
 
 Session.CallFunction fn
 
 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
 
End Sub