Getting started with SAPUI5
A while back I had the opportunity to investigate SAPUI5 as an option for user interfaces on our current project. Here is a quick little getting started guide that I wrote back then, partly for my own benefit in case I ever need to get started on it again.
SAPUI5, SAP’s UI development tookit for HTML5 development, Â is an exciting framework for building fancy, single page web applications. There is a lot of information about it already, but I thought I would write down a getting started guide that is hopefully easy to follow, without bombarding you with all the background knowledge. (I will save that for the end).
You should hopefully end up with an easy-to-use setup that will give you a simple workflow for creating and testing SAPUI5 applications, in the process hopefully saving you the pain of figuring out what to do.
In the process we will be developing a simple application that consumes services from services.odata.org (not from your SAP system at present, I will explain toward the end why). The end result will be a simplistic page that shows a list of customers, and orders for those customers when one of them is selected.
To begin, you will need the following:
- A version of Java installed (I have 1.7.0_21) – get it here
- Eclipse for Java EE Developers (Juno) – get it here
- Apache Tomcat version 7 archive (zip) distribution – get it here
- SAP UI Development Toolkit for HTML 5 (Evaluation) – get it here
Step 1: Setting up a test server environment
I will assume you have Java installed already. Ensure you have the JRE_HOME environment variable set to the location of the JRE, for example C:\Program Files\Java\jre7.
Unzip your Tomcat distribution to somewhere on your hard drive. From now on, I will refer to the location where you unzipped it (e.g. C:\temp\apache-tomcat-7.0.39) as TOMCAT_HOME. (You don’t have to set the environment variable, it’s just a useful reference).
Next, create a folder somewhere and unzip the SAPUI5 evaluation toolkit (my file is called HTML5Evaluation_complete_1.12.1.zip). Let’s call this SAPUI5_HOME for now.
Open up the command shell and navigate to TOMCAT_HOME\bin. Run startup.bat to launch Tomcat, which will open a new console window in which it shows the output of the server. Once you see that it has started up, copy sapui5.war and sapui5-sdk.war to TOMCAT_HOME\webapps. Give the two .war files a little time to auto-deploy. After this, you will have the complete documentation and Javascript libraries available on the server. Navigate to http://localhost:8080/sapui5-sdk/ to view the documentation.
In the command prompt you had open, run shutdown.bat to stop the server again. We will start it again from Eclipse later on.
Step 2: Setting up the development environment
In the next step, we will set up the Eclipse Workbench, install the SAP plugins and set up the connection to the Tomcat development server.
Extract the Juno Java EE Eclipse archive. Start Eclipse by double-clicking eclipse.exe. In the Eclipse Workbench, choose Help -> Install New Software… from the menu.
In the dialog that comes up, choose “Add…”, then, in the Add Repository dialog, click “Local…” and select the SAPUI5_HOME/tools-updatesite folder. Give the new repository a name, like SAPUI5.


Click OK and go through the wizard to add the components to the workbench, (click Next, Accept the License and click Finish) then restart the workbench. This will require a considerable number of components to be downloaded from the internet, so make sure you are connected.

When Eclipse has restarted, navigate to the Servers view and create a new server definition.

Select “Tomcat v7.0 Server” under the Apache section. In the next page of the wizard, choose the TOMCAT_HOME directory and finish the wizard. Once done, double-click the server definition to open up the properties page. Under “Server Locations”, select “Use Tomcat installation (takes control of the Tomcat installation)”.

You can optionally also set the deploy path to TOMCAT\webapps, otherwise a new folder is created under your Tomcat installation, which should not cause a problem, but do this just to be safe.
Make sure to save the Properties page, and then we can start developing.
Step 3: Develop a SAPUI5 application
In this step, we finally create the SAPUI5 application.
From the Eclipse menu, choose File -> New -> Other…. Â Under “SAPUI5 Application Development”, choose “Application Project”.

Let’s call the project “northwind”, after the famous sample schema shipped with SQL Server. (After all, the data is coming from that same set).

We need to specify a default view. The generated code will load this view into the start page, and this is where we will specify our code. We will call our view “customer-orders” and then we can complete the wizard. Leave Javascript as the default (views can be written in JSON and XML as well).
The generated project contains an index.html file and a folder with the same name as the project (“northwind” in our case). If you open up the index.html file, you will see that there is generated code to load the view specified in the project creation wizard.

The view consists of two files: customer-orders.js and customer-orders.controller.js. The controller contains some functions that are called during various stages in the view’s lifecycle, and you can add additional functions that are called from your own view components.
As a first step, open index.html and change the following lines:
to this:
This causes the runtime to load an additional library with table UI components, which we are using in this example.
Now we will add some code to the view. Open up the customer-orders.js file. Copy and paste the following lines of code into the createContent function body in this file:
var aControls = [];
var oModel = new sap.ui.model.odata.ODataModel("http://services.odata.org/Northwind/Northwind.svc/", false);
//---- CUSTOMER TABLE
var customerTable = new sap.ui.table.Table({
title: "Customers",
visibleRowCount: 7,
selectionMode: sap.ui.table.SelectionMode.Single
});
//---- CUSTOMER TABLE COLUMNS
var customerTableColumns = [
{text: "Customer ID", property: "CustomerID"},
{text: "Company Name", property: "CompanyName"},
{text: "Contact Name", property: "ContactName"}
];
customerTableColumns.forEach(function(column){
customerTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: column.text}),
template: new sap.ui.commons.TextView().bindProperty("text", column.property),
sortProperty: column.property,
filterProperty: column.property,
width: "75px",
hAlign: "Center"
}));
});
//---- ORDER TABLE
var orderTable = new sap.ui.table.Table({
title: "Orders",
visibleRowCount: 5,
selectionMode: sap.ui.table.SelectionMode.None
});
//---- ORDER TABLE COLUMNS
var orderTableColumns = [
{text: "Order ID", property: "OrderID"},
{text: "Order Date", property: "OrderDate"},
{text: "Required Date", property: "RequiredDate"},
{text: "Shipped Date", property: "ShippedDate"}
];
orderTableColumns.forEach(function(column){
orderTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: column.text}),
template: new sap.ui.commons.TextView().bindProperty("text", column.property),
sortProperty: column.property,
filterProperty: column.property,
width: "75px",
hAlign: "Center"
}));
});
//Create a model and bind the table rows to this model
customerTable.setModel(oModel);
customerTable.bindRows("/Customers"); // Fill customer table with customer records
orderTable.setModel(oModel);
// Handle row selection event
customerTable.attachRowSelectionChange(function (event) {
// Select orders for the selected customer
// (using Odata navigation defined in metadata for Customers)
var selectedRowContext = event.getParameter("rowContext");
var selectedOrders = selectedRowContext + "/Orders";
orderTable.bindRows(selectedOrders);
});
// Return controls in this view
aControls.push(customerTable);
aControls.push(orderTable);
return aControls;
Step 4: Run!
Now we will launch and test our application.
In the Servers view, right-click the server definition and choose "Add and Remove..." from the context menu. In the dialog that comes up, add your new project to the list of Configured resources.

Click Finish and start the server by clicking the green Play button. If all goes well, the console view will show that the server started successfully.
Now we can view the application - almost. Due to a security issue, you may not be able to run this application directly in your browser without a workaround.
If you are running Chrome, you should start a new instance with
chrome.exe --disable-web-security
To force a new instance of Chrome (if it is still running) with a separate data directory, do as follows (you must navigate to the Chrome installation folder first):
chrome.exe --user-data-dir="C:/temp/chromedev" --disable-web-security
This will bypass the security restrictions and allow the data to be retrieved remotely. I didn't have to do this for Internet Explorer (IE 9, I am using Windows 7), which is not a great sign.
Navigate to http://localhost:8080/northwind/. If all goes well, the application should come up as in the screenshot. Selecting a customer in the upper table will cause orders for that customer to be retrieved and displayed in the lower table.

What's behind it all?
Now that you have seen SAPUI5 in action, we can get into some of the background detail.
SAPUI5 is essentially just a toolkit for developing HTML5 web applications. If you have worked with other frameworks or toolkits like Dojo or Kendo UI, then you have a good idea what it is about; it includes UI components, Ajax components and data binding between controls and your data for the most part, as well as functions to support MVC development.
But the secret sauce is something else: a protocol for exchanging data and metadata called the Open Data Protocol, or OData for short. OData is a specification developed and released to the public by Microsoft, which is quickly gaining adoption among some big players. Basically, it specifies a very uniform way to represent and access data and related metadata in XML format, thus allowing end-user applications to be developed that straddle multiple systems with the greatest of ease. (Systems which act as OData providers, of course). SAPUI5 acts as an OData client in this instance.
If you have developed with the Business Object Layer in ABAP (most likely in SAP CRM) , then you can relate to the concept: the BOL too provides a  uniform layer to access data, regardless of its source (albeit limited to an ABAP system) that makes application programming very easy.
The data we consumed in this example is hosted on the OData website, and you can take a look at it in its raw form at the following URL: http://services.odata.org/Northwind/Northwind.svc/. OData makes use of a number of conventions; accessing the metadata for the collections you saw in the previous URL is obtained by visiting /Northwind/Northwind.svc/$metadata on the same server. (Note that I am using relative URLs from here). A list of customers (shown as a collection in the data retrieved from the first URL) is retrieved with /Northwind/Northwind.svc/Customers, a single customer is accessed by its key with /Northwind/Northwind.svc/Customers('BONAP'), orders for that customer are given through /Northwind/Northwind.svc/Customers('BONAP')/Orders and so on.
SAP also has a solution which you can use to expose data from an ABAP system using the OData protocol. It is called the SAP Netweaver Gateway. SAP Netweaver Gateway is an OData provider. The reason we didn't use it to demonstrate is that you will need to install Gateway as an add-on to your existing system. (You can obtain an evaluation copy of SAP Netweaver Gateway with a basic ABAP system from SAP Community Network).
Where to from here?
Judging by the buzz on SCN, SAPUI5 is the way forward as far as user interfaces go for SAP. SAP have dabbled in a number of web-based interfaces since ITS: There has been BSP, Web Dynpro (Java and ABAP) and more recently SAP Web Client, the framework extracted from SAP CRM, built on top of BOL. The two latter frameworks have done an excellent job of completely isolating any HTML coding from the developer. All these solutions are great, if your intent is only to access an SAP system. However, with heterogeneous system access becoming more important, OData-based solutions such as SAPUI5 and SAP Netweaver Gateway will possibly provide the right framework.
Having said that, SAPUI5 is by no means perfect. For example, there is no currency field, as you would find in Dojo, which is very strange when you consider that this is SAP delivering this solution, and a currency field should be the first thing to include. In addition, once you delve deeper into the API, there seem to be a few rough edges and shortcomings, but I am sure those will be ironed out in future releases.
Within ABAP circles, there is a lot of trepidation when it comes to web development, yet it is not something new in the SAP sphere. ABAP developers seem to like their comfort and  stability and I have met hardly any who take any interest whatsoever in software development outside of work or outside of ABAP. On the other hand, I have met a few ABAP developers who do web development on the side for fun and/or profit. There is no reason not to consider web interfaces as an integral part of the SAP development experience, though, and this is maybe a good time to jump in.
Leave a Reply