Professional Documents
Culture Documents
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
TABLE OF CONTENTS
INFORMATION ................................................................................................................................................. 3
WEEK 5 UNIT 3................................................................................................................................................. 4
Exercise ............................................................................................................................................................ 4
Solution ............................................................................................................................................................ 8
WEEK 5 UNIT 4............................................................................................................................................... 15
Exercise .......................................................................................................................................................... 15
Solution .......................................................................................................................................................... 16
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Welcome to the exercises and solutions of week 5 of the openSAP course Developing Mobile Apps
with SAP HANA Cloud Platform.
INFORMATION
In the following exercises we will go through building a hybrid application based on UI5 with SAP Web IDE
that supports offline use. You will be guided through using a SAP Web IDE template to create a offline app.
Following that you will deploy the offline app to an Emulator/Simulator or Device and test it.
Please Note: the performance of this offline app will be poor due to the HCPms Trial landscape and limited
resource. Depending on use at the time, flushing and refreshing your offline store can take up to 2 minutes
(normally around the 1 minute mark, sometimes much less).
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
WEEK 5 UNIT 3
Exercise
Objective
In this exercise you will learn how to create and configure a hybrid application using the SAP Web IDE offline
template.
Exercise Description
Logon to the your SAP Web IDE trial account.
Create a new Template Project. File > New > Project From Template
Select Template: A SAPUI5 Master Detail Kapsel Offline Application
Click Next to start the template wizard.
Name the Project: OfflineOpenSAPApp. Click Next.
On the Data Connection screen select Service URL as your source.
Select your service destination from the dropdown and then enter the OData Service URL you have
been using in the input field (make sure /V2 is in the same spot show below):
Click Next.
In the Offline Data Entity Collections screen select the Products and Suppliers collections.
Click Next.
On the Template Customizations screen in the Project Settings area enter the Project Namespace:
com.sap.open.offline
In the Master Section enter the following:
Title
Products
OData Collection
Products
Search Placeholder
Name
Search Tooltip
Enter Product Name
Search Field
Name
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Name
Price
ID
Product Details
Name
Description
Supplier
Name
Address/City
Address/State
In the Create/Edit Section you can select the Create Input Fields for Key Properties checkbox. This will
generate some input fields for the key fields.
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Highlight the Project node and click the Run button on the menu bar to launch the application.
In the Web IDE right click on the project node of the OfflineOpenSAPApp project and select Project
Settings.
In the Project Settings go to Device Configuration.
Set the App Name: OfflineOpenSAPApp
Set the App ID: com.sap.open (the application configuration you created on HCPms).
Enter the Version: 1.0.0
Select the Device Platform you will be running on (Android or iOS).
From the Cordova plugins select Debug Console and Network Connection.
From Kapsel plugins select Logon Manager and Offline OData.
Save your changes.
Open the devapp.js file found in the projects dev folder.
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
In the Application Contructor area find the var s definition. This is the line of code that defines the
defining requests that are used for creating the Offline Store. Comment out the var s line of code
which assumes the OData Service supports delta queries. Replace it with the var s line of code
shown below (copy it from the txt file associated with this exercise, copying from a PDF will result in
errors)
var s = "{"Products":"/Products?$expand=Supplier"}";
This line of code sets up the defining requests to load both Products and their related Suppliers with a
single defining request which is recommended when the backend doesnt support delta queries. Your
code should now look like the following:
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Solution
Explanation
1. Logon to your SAP Web IDE
Trial Account
Screenshot
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
6. On the Data Connection screen
select Service URL as your
Source.
Screenshot
8. On the Template
Customizations screen in the
Project Settings area enter the
Project Namespace:
com.sap.open.offline
9. In the Master Section enter the
following:
Title
OData Collection
Search Placeholder
Search Tooltip
Search Field
Products
Products
Name
Enter Product Name
Name
Item Title
Numeric Attribute
Name
Price
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
Screenshot
Units Attribute
ID
Title
Additional Attribute1
Additional Attribute2
Product Details
Name
Description
OData Navigations
Navigations Attribute1
Navigation Attribute2
Navigation Attribute3
Supplier
Name
Address/City
Address/State
10
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
14. Click the Finish button to
complete the wizard and generate
your project.
Screenshot
11
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
15. In the Web IDE right click on
the project node of the
OpenSAPApp project and select
Project Settings:
Screenshot
App Name
App ID
Version
OfflineOpenSAPApp
com.sap.open
1.0.0
12
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
Screenshot
13
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
Since the OData Service we are
using doesnt support delta
queries, we are going to change it
to load the supplier data with a
$expand. So instead of having 2
defining requests (Products and
Suppliers), we will have one that
loads all Products and their
related Suppliers.
24. Comment out the var s = line
of code.
Screenshot
var s =
"{"Products":"/Products?$expand=Supplier"}";
14
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
WEEK 5 UNIT 4
Exercise
Objective
In this exercise, you will use the SAP Hybrid Application Toolkit to deploy to build your Web IDE application
as a hybrid native application and run it on a device or emulator. You will then test the offline functionality of
the app.
Exercise Description
Uninstall the OpenSAPApp on your device. Both apps have the same app ID (com.sap.open), so as
far as the device knows, they are the same. So you should clear that app off the device before
proceeding.
Start the SAP Hybrid Application Toolkit (HAT).
o Open a Command Prompt / Terminal and change directory to your HAT installation folder.
o On Windows execute: run.cmd
o On OS X execute: run.sh
Logon to your SAP Web IDE trial account.
Right click on the OfflineOpenSAPApp project node and in the context menu select Run > Run on >
<Device/Simulator/Emulator>
This will start the process of building and deploying the app. It can take some time. Open the Console
on the Web IDE to view status updates. Web IDE menu path: View > Console
When the application is deployed to the Device/Emulator/Simulator it will be opened.
Logon to the app with your HCP Trial user and password.
Enter a passcode or disable it completely. Click Submit to display the initial application screen.
Note: to enforce entering a passcode, go to your HCPms application configuration and on the Client
Policies tab select the Enable Password Policy checkbox. And set any further password
configuration details.
The application will be displayed.
Note: it will take a few seconds to load the Offline Store DB, so the product list will be delayed during
this time.
Select a product in the list. Go into change mode for the product and change the description. Save the
changes.
Select another product. Delete it.
If you are using a device, turn airplane mode on. And see that you can still view and edit the data in
the app.
Make sure you turn airplane mode off if you are on a device and that you are connected back to the
network.
On the Product List view, click the flush/refresh button (bottom left hand corner). This will cause Offline
Store to be Flushed, if the flush is successful, the Refresh is called.
Please Note: the performance of this offline app will be poor due to the HCPms Trial landscape and
limited resource. Depending on use at the time, flushing and refreshing your offline store can take up
to 2 minutes (normally around the 1 minute mark, sometimes much less).
Once the flush/refresh is finished, go and call user OData Service Products entity set with a REST
Client and make sure the data has been changed there.
Thats it! You have completed the exercise of creating a secure online application!
15
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Solution
Uninstall the OpenSAPApp on your device. Both apps have the same app ID (com.sap.open), so as far as
the device knows, they are the same. So you should clear that app off the device before proceeding.
Explanation
1. Start the SAP Hybrid
Application Toolkit (HAT).
Screenshot
16
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
3. Right click on the
OfflineOpenSAPApp project node
and in the context menu select
Run > Run on >
<Device/Simulator/Emulator>
Screenshot
17
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
6. When the application is deploy
to the Device/Emulator/Simulator
it will be opened.
Screenshot
Click Register.
18
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
Screenshot
19
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
Navigate around the application.
Screenshot
20
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
10. Select a product in the list. Go
into change mode for the product
and change the description. Save
the changes.
Screenshot
21
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
11. Open select a product in the
list. Delete it.
Screenshot
22
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
12. Back in the Product List view
notice that the changed product is
updated and the deleted products
are no longer in the list.
Screenshot
23
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
14. Submit the changes on the
device.
Screenshot
24
openSAP Developing Mobile Apps with SAP HANA Cloud Platform: Week 5 - Exercises and Solutions
Explanation
15. Once the flush/refresh is
finished. Execute the REST client
call to the Products entity set.
Ensure that your changes are
reflected there.
Screenshot
25
www.sap.com