Platforms to show: All Mac Windows Linux Cross-Platform
/Tools/RFC/XOJO_SAP_RFC_sample
Required plugins for this example: MBS Tools Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Tools/RFC/XOJO_SAP_RFC_sample
This example is the version from Mon, 17th Jan 2021.
Project "XOJO_SAP_RFC_sample.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
AllowAutoQuit = true
End EventHandler
Property ConnectionToSAP As RFCConnectionMBS
End Class
Class flights Inherits Window
Const gc_CARRID = "ID"
Const gc_CONNID = "Nr."
Const gc_CURRENCY = "Währung"
Const gc_Carrier = "Fluggesellschaft"
Const gc_ConnectToSAP = "mit SAP-System verbinden"
Const gc_ConnectionStateOff = "nicht verbunden"
Const gc_ConnectionStateOn = "verbunden"
Const gc_FLDATE = "Flugdatum"
Const gc_GrpLogOnData = "SAP Anmeldedaten"
Const gc_PAYMENTSUM = "Akt. Buchungssumme"
Const gc_PLANTYPE = "Flugzeugtyp"
Const gc_PRICE = "Flugpreis"
Const gc_SEATSMAX = "Kapazität"
Const gc_SEATSMAX_B = "Kapazität BC"
Const gc_SEATSMAX_F = "Kapazität FC"
Const gc_SEATSOCC = "Belegt"
Const gc_SEATSOCC_B = "Belegt BC"
Const gc_SEATSOCC_F = "Belegt FC"
Const gc_SystemNumber = "Instanz-Nr."
Const gc_TitleFlights = "SAP RFC Beispiel"
Const gc_client = "Mandant"
Const gc_host = "Anwendungsserver"
Const gc_language = "Sprache"
Const gc_message_NoCarrier = "Keine Fluggesellschaft gefunden"
Const gc_password = "Passwort"
Const gc_user = "Benutzer"
Control GrpLogOn Inherits GroupBox
ControlInstance GrpLogOn Inherits GroupBox
EventHandler Sub Open()
me.Caption = gc_GrpLogOnData
End EventHandler
End Control
Control Label_ashost Inherits Label
ControlInstance Label_ashost Inherits Label
EventHandler Sub Open()
me.Value = gc_host
End EventHandler
End Control
Control logon_ashost Inherits TextField
ControlInstance logon_ashost Inherits TextField
End Control
Control Label_sysnr Inherits Label
ControlInstance Label_sysnr Inherits Label
EventHandler Sub Open()
me.Value = gc_SystemNumber
End EventHandler
End Control
Control logon_sysnr Inherits TextField
ControlInstance logon_sysnr Inherits TextField
End Control
Control Label_client Inherits Label
ControlInstance Label_client Inherits Label
EventHandler Sub Open()
me.Value = gc_client
End EventHandler
End Control
Control logon_client Inherits TextField
ControlInstance logon_client Inherits TextField
End Control
Control logon_user Inherits TextField
ControlInstance logon_user Inherits TextField
End Control
Control Label_user Inherits Label
ControlInstance Label_user Inherits Label
EventHandler Sub Open()
me.value = gc_user
End EventHandler
End Control
Control Label_passwd Inherits Label
ControlInstance Label_passwd Inherits Label
EventHandler Sub Open()
me.Value = gc_password
End EventHandler
End Control
Control logon_passwd Inherits TextField
ControlInstance logon_passwd Inherits TextField
End Control
Control logon_lang Inherits TextField
ControlInstance logon_lang Inherits TextField
EventHandler Sub Open()
var lv_Locale as xojo.core.locale = xojo.core.locale.current
me.value = lv_Locale.Identifier.Left(2).Uppercase
End EventHandler
End Control
Control Label_lang Inherits Label
ControlInstance Label_lang Inherits Label
EventHandler Sub Open()
me.Value = gc_language
End EventHandler
End Control
Control Label_airline Inherits Label
ControlInstance Label_airline Inherits Label
EventHandler Sub Open()
me.Value = gc_Carrier
End EventHandler
End Control
Control PopupSCARR Inherits PopupMenu
ControlInstance PopupSCARR Inherits PopupMenu
EventHandler Sub Change()
var carrier(-1) as string = split(PopupSCARR.SelectedRowValue," ")
if carrier.Ubound > -1 then
Call_ZXOJO_GET_SFLIGHT(carrier(0))
end if
End EventHandler
End Control
Control ListboxSFLIGHT Inherits Listbox
ControlInstance ListboxSFLIGHT Inherits Listbox
EventHandler Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) As Boolean
If row Mod 2 = 0 Then
g.ForeColor = FillColor
g.FillRectangle(0, 0, g.Width, g.Height)
End If
End EventHandler
EventHandler Sub Open()
me.HeaderAt(00) = gc_CARRID
me.HeaderAt(01) = gc_CONNID
me.HeaderAt(02) = gc_FLDATE
me.HeaderAt(03) = gc_PRICE
me.HeaderAt(04) = gc_CURRENCY
me.HeaderAt(05) = gc_PLANTYPE
me.HeaderAt(06) = gc_SEATSMAX
me.HeaderAt(07) = gc_SEATSOCC
me.HeaderAt(08) = gc_PAYMENTSUM
me.HeaderAt(09) = gc_SEATSMAX_B
me.HeaderAt(10) = gc_SEATSOCC_B
me.HeaderAt(11) = gc_SEATSMAX_F
me.HeaderAt(12) = gc_SEATSOCC_F
End EventHandler
End Control
Control PushButtonConnect Inherits PushButton
ControlInstance PushButtonConnect Inherits PushButton
EventHandler Sub Action()
ConnectSAPSever()
End EventHandler
EventHandler Sub Open()
me.Caption = gc_ConnectToSAP
End EventHandler
End Control
Control LabelConnectionState Inherits Label
ControlInstance LabelConnectionState Inherits Label
EventHandler Sub Open()
me.Value = gc_ConnectionStateOff
End EventHandler
End Control
EventHandler Function KeyDown(Key As String) As Boolean
Select case key.asc
case 13 // Enter-Taste
ConnectSAPSever()
case 27
me.close
end select
End EventHandler
EventHandler Sub Open()
BildschirmFelderSperren(true)
self.Title = gc_TitleFlights
End EventHandler
Sub BildschirmFelderSperren(iv_sperren as boolean, iv_Scope as string = "all")
// --------------------------------------------------------------------------------
// - BildschirmFelderSperren
// --------------------------------------------------------------------------------
// - Sperren und entsperren von Bildschirmfeldern. Gesperrte Felder werden
// - ausgegraut, entsperrte Felder werden weiß eingefärbt. Checkboxen und
// - Radioknöpfe werden nur aktiviert oder deaktiviert.
// --------------------------------------------------------------------------------
// - --> iv_sperren - Sperre an oder aus
// - --> iv_Scope - Bildschirmbereich
// --------------------------------------------------------------------------------
var lv_sperren as Boolean
var lv_enabled as Boolean
var lv_BackColor as Color
var lv_ColorProtected as color = FillColor // grau &cCCCCCC
var lv_ColorOpen as color = &cFFFFFF // weiß &cFFFFFF
// Das Programm hat einen Anzeige- und einen Änderungsmodus.
// Im Anzeigemodus kann nichts verändert oder gespeichert werden.
// Alle folgenden existierenden Felder in Abhängigkeit von APP.MyModus
// auf ReadOnly = true oder false gesetzt.
'if app.MyModus = app.gc_ModusAnzeige then
'lv_sperren = true
'lv_enabled = false
'else
lv_sperren = iv_sperren
if iv_sperren then
lv_enabled = false
else
lv_enabled = true
end if
'end if
if lv_sperren then
lv_BackColor = lv_ColorProtected
else
lv_BackColor = lv_ColorOpen
end if
if iv_Scope = "all" then
PopupSCARR.Enabled = lv_enabled
'if not lv_enabled then
'PopupSCARR.SelectedRowIndex = -1
'end if
ListboxSFLIGHT.Enabled = lv_enabled
end if //iv_Scope = "alles" oder "AutoDoc"
End Sub
Sub Call_ZXOJO_GET_SCARR()
// -------------------------------------------------------------------------------
// - Method Call_ZXOJO_GET_SCRARR
// -------------------------------------------------------------------------------
// - This method reads SAP table SCARR which contains all airlines of the example
// - and fills the PopupSCARR to enable any selections
// -------------------------------------------------------------------------------
PopupSCARR.RemoveAllRows
var fd As RFCFunctionDescriptionMBS = app.ConnectionToSAP.FunctionDescription("ZXOJO_GET_SCARR")
var f As RFCFunctionMBS = fd.CreateFunction
f.Invoke
var SCARR as RFCTableMBS = f.TableValue("ET_SCARR")
// something found in SAP table SCARR?
if SCARR.RowCount < 1 then
MessageBox(gc_message_NoCarrier)
return
end if
var carrier as string
SCARR.MoveToFirstRow
for iRow as integer = 1 to SCARR.RowCount
carrier = SCARR.StringValue("CARRID")+" "+SCARR.StringValue("CARRNAME")
PopupSCARR.AddRow(carrier)
if irow < SCARR.RowCount then
SCARR.MoveToNextRow
end if
next
End Sub
Sub Call_ZXOJO_GET_SFLIGHT(iv_CarrID as string)
// -------------------------------------------------------------------------------
// - Method Call_ZXOJO_GET_SFLIGHT
// -------------------------------------------------------------------------------
// - This method reads SAP table SFLIGHT which contains all flights of the example
// - and fills the ListboxSFLIGHT
// -------------------------------------------------------------------------------
ListboxSFLIGHT.RemoveAllRows
var fd As RFCFunctionDescriptionMBS = app.ConnectionToSAP.FunctionDescription("ZXOJO_GET_SFLIGHT")
var f As RFCFunctionMBS = fd.CreateFunction
f.StringValue("IV_CARRID") = iv_CarrID
f.Invoke
var SFLIGHT as RFCTableMBS = f.TableValue("ET_SFLIGHT")
// something found in SAP table SFLIGHT?
if SFLIGHT.RowCount < 1 then
var s As RFCStructureMBS = f.StructureValue("ES_MESSAGE")
MessageBox( s.StringValue("MESSAGE") )
return
end if
var fldate as string
SFLIGHT.MoveToFirstRow
for iRow as integer = 1 to SFLIGHT.RowCount
fldate = SFLIGHT.StringValue("FLDATE")
select case logon_lang.Value
case "DE"
fldate = fldate.Middle(6,2)+"."+fldate.Middle(4,2)+"."+fldate.left(4)
case "EN"
fldate = fldate.Middle(4,2)+"-"+fldate.Middle(6,2)+"-"+fldate.left(4)
end select
ListboxSFLIGHT.AddRow(SFLIGHT.StringValue("CARRID") _
, SFLIGHT.StringValue("CONNID") _
, fldate _
, SFLIGHT.StringValue("PRICE") _
, SFLIGHT.StringValue("CURRENCY") _
, SFLIGHT.StringValue("PLANETYPE") _
, SFLIGHT.StringValue("SEATSMAX") _
, SFLIGHT.StringValue("SEATSOCC") _
, SFLIGHT.StringValue("PAYMENTSUM") _
, SFLIGHT.StringValue("SEATSMAX_B") _
, SFLIGHT.StringValue("SEATSOCC_B") _
, SFLIGHT.StringValue("SEATSMAX_F") _
, SFLIGHT.StringValue("SEATSOCC_F"))
if irow < SFLIGHT.RowCount then
SFLIGHT.MoveToNextRow
end if
next
End Sub
Sub ConnectSAPSever()
if logon_ashost.Value = "" or logon_client.value = "" or logon_sysnr.Value = "" or _
logon_user.Value = "" or logon_passwd.Value = "" or logon_lang.Value = "" then
MessageBox("Logon parameter incomplete")
return
end if
#If TargetWin32
var LibFile as string = "sapnwrfc.dll"
#Else
// get the actual folder
var MacOsFolder as folderitem = app.ExecutableFile.Parent
System.EnvironmentVariable("DYLD_LIBRARY_PATH") = MacOsFolder.NativePath
If System.EnvironmentVariable("DYLD_LIBRARY_PATH") = "" Then
MessageBox("DYLD_LIBRARY_PATH variable not set")
return
end if
var LibFile as FolderItem = MacOsFolder.Child("libsapnwrfc.dylib")
var LibPath As String = LibFile.parent.NativePath
Call RFCModuleMBS.SetCurrentWorkingDirectory(libPath)
#EndIf
If not RFCModuleMBS.LoadLibrary(LibFile) Then
MessageBox("Failed to load library")
MessageBox RFCModuleMBS.LibraryLoadErrorMessage
return
End If
'msgbox RFCModuleMBS.Version
'fz.message(gc_msgty_i, RFCModuleMBS.Version)
'Break
var loginParams As New Dictionary
loginParams.Value("ashost") = logon_ashost.Value
loginParams.Value("sysnr") = logon_sysnr.Value
loginParams.Value("client") = logon_client.Value
loginParams.Value("user") = logon_user.Value
loginParams.Value("passwd") = logon_passwd.Value
loginParams.Value("lang") = logon_lang.Value
app.ConnectionToSAP = New RFCConnectionMBS(loginParams)
LabelConnectionState.Value = gc_ConnectionStateOn
Call_ZXOJO_GET_SCARR()
BildschirmFelderSperren(false)
Exception r As RFCErrorExceptionMBS
LabelConnectionState.Value = gc_ConnectionStateOff
MessageBox r.message
End Sub
Note "Bemerkungen / Remarks"
Capacity BC means maximum capacity in business class
Capacity FC means maximum capacity in first class
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project
The items on this page are in the following plugins: MBS Tools Plugin.