Enterprise Connectors allows you to connect from Delphi and C++ Builder to 80+ enterprise data sources: https://www.embarcadero.com/products/enterprise-connectors.
Between these data sources, we have SAP, one of the most used ERPs in the world.
To demonstrate how easy is to connect SAP using the Enterprise Connectors with FireDAC, I decided to build a native mobile client for Android and iOS, using Delphi and FMX on the client side, and RAD Server/FireDAC on the server side.
Solution overview
In summary, the idea is to allow a mobile application to display data directly from SAP in real time, for example, showing a summary of the sales in a period.
To accomplish this task we’ll have a FireDAC SAP connection in our RAD Server implementation, which will allows us to query the Sales Document entity via NetWeaver: http://www.se80.co.uk/saptables/v/vbak/vbak.htm
The cool thing from the Enterprise Connectors is that, you basically can issue standard SQL ANSI queries against any supported data source, easy as 1,2,3.
Server Implementation
Our server application is actually a RAD Server application used to publish the REST APIs that we’ll need. Before starting, I have installed the SAP driver from the Enterprise Connectors collection that are available in the GetIt as a trial: https://community.embarcadero.com/blogs/entry/enterprise-connectors-are-now-live
Our server has just one method, responsible for grabbing the data from the VBAK entity, which is serialized as JSON using the TFDSchemaAdapter:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
procedure TSAPEMSServerResource1.Get(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse); var fMem: TMemoryStream; begin fMem := TMemoryStream.Create; try VbakView.Open; FDSchemaAdapter1.SaveToStream(fMem, TFDStorageFormat.sfJSON); AResponse.building.SetStream(fMem, 'application/json', True); except on E: Exception do begin fMem.Free; raise; end; end; end; |
Mobile Client Implementation
Our client application has a ListView using the Dynamic Appearance style to display the sales data, and a TChart displaying the sales total by department.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
procedure TMainForm.FormCreate(Sender: TObject); begin chartResult.Series[0].Clear; end; procedure TMainForm.SpeedButton1Click(Sender: TObject); var i: integer; MyThread: TThread; begin EMSFireDACClient1.GetData; FDMemTable1.Open; FDConnection1.Open; FDQuery1.Open; MyThread := TThread.CreateAnonymousThread( procedure begin while not FDQuery1.Eof do begin TThread.Synchronize(MyThread, procedure begin chartResult.Series[0].Add(FDQuery1.FieldByName('TOTAL').AsFloat, FDQuery1.FieldByName('VKORG').AsString); end); FDQuery1.Next; end; end); MyThread.Start; end; |
One thing to notice in the code above, I’m using the FireDAC’s LocalSQL feature to execute one SQL query that summarize the data and fills the graph in the client side, avoiding additional calls to the server (in this case NetWeaver) and increasing the client performance.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition