Keep Mobile Simple
When talking about Mobile apps with Offline capabilities and the capacity to run on different kind of devices, most customers automatically think these apps will cost a lot of money. Depending on the Use case this is not always true. Recently I received the question of one of my customer to renew a mobile App written in VB.NET using SOAP Services to access data from SAP. With SAP Gateway and Fiori, the customer wanted to make this mobile app completely with SAP Technology! The new app should also support multiple Devices with different OS types. (The old one only runs on Windows Phone 6.5). The two big challenges of this question are:
- Support multiple devices
- Offline capability
Support multiple devices
For supporting multiple devices, we’ve chosen to create a Hybrid Mobile app. With a Hybrid app you have only one Codebase to support multiple target devices. We followed SAP and used the SAPWebIDE which enables us to create Mobile Fiori apps based on Cordova. With Cordova we could transform a Web app (like Fiori) into a Mobile app. The SAPWebIDE has the ability to generate such a Cordova project from your Fiori project. You only have to install the Hybrid App Toolkit on your computer.
The Hybrid App Toolkit made it astonishing easy to support multiple devices. In the SAPWebIDE I could configure my Cordova project and select the target devices. When everything was configured, I could deploy my Fiori app to my local computer. On my local computer I could just run the generated Cordova project.
There is also the Fiori Mobile Service in the SAP Cloud Platform. With this Cloud service you even don’t need to install anything.
This part was mainly covered thanks to the SAPWebIDE and the Hybrid App Toolkit. The only difficult part was the installation of the Hybrid App Toolkit. But there are some great blogs that explain everything step by step.
Offline capabilities in the app were another discussion. When we talk about offline we often think we need a middle layer and as SAP developers we think of the SAP Cloud Platform Mobile Services or SAP Mobile Platform. These platforms cost money. The question is, do we always need these platforms for offline?
In our case the Offline scenario was very basic.
- Get all the data in the morning
- Work all day on the offline data
Send back all the data of the device to the SAP system in the evening
With this simple offline scenario and if you know that this app will only be used in the private network, there is no need for SAP Mobile Platform or SAP CP Mobile Services.
Okay, we don’t use the SMP or CPms. This also means we cannot use the Kapsel plugins. Kapsel plugins are Cordova plugins created by SAP. Instead of using Kapsel plugins for offline storage we’ve used a free and open source Cordova SQLite plugin. With this plugin we can use the offline storage of the mobile device but we’ll have to implement the logic ourselves.
SQLite plugin: https://www.npmjs.com/package/cordova-sqlite-plugin
In the app, I separated the logic is multiple logical blocks to support offline and online capabilities. Here you have a short explanation about the most internal architecture of the app. The most important blocks for the offline and online part:
- Gateway service
- Database Service
- Database Helper
- Data Persistence Layer
As we used a Cordova SQLite plugin and not the Offline Kapsel plugin, I had to create my own service to handle the communication between the app and the local database of the device. The service contains multiple functions to access the data offline by using the Cordova SQLite plugin. The functions in this service are designed to create database queries by passing JSON objects with all the required specifications. For example we could just access a table by passing the table name and the SQL “where” condition as a JSON object. This made it easier in our Controllers to access the local database.
For generating all the SQL statements and the fields of a table we created a Database Helper. This helper object contains multiple conversion functions from JSON to SQL.
Data Persistence Layer
I created this layer to support devices that don’t support Offline, for example the web browser. This layer will check if it’s a mobile device. If it’s a mobile device, it will use the local database. When it’s not a mobile device, it will use the gateway service and access data from SAP real time. The controllers of the views just access the data persistence layer and this layer will handle the request. This enabled us to run the app as a normal Fiori app and as a mobile app.
In this project I also used a BarCodeScanner, you can read more about it on: https://blogs.sap.com/2017/02/18/custom-cordova-plugin-mobile-hybrid-app/
Mobile doesn’t have to be expensive or complex. Depending on the case you can do it cheap and simple. Don’t get me wrong, SMP and CPms are real good products but it’s just not always required. It may take some more time to develop the offline functionality but it will save you money on the long term. No monthly fee for CPms or hardware costs for SMP.
Device independent apps do not exist! We can adapt as many devices as possible but we need to test each device.
Last but not least, SAPWebIDE is a great tool for building Hybrid Mobile apps!.