You are on page 1of 38

MOB260 Data to Go: Learn to implement Offline

in Mobile Apps

Public
Speakers

Las Vegas, Sept 19 - 23 Bangalore, October 5 - 7 Barcelona, Nov 8 - 10

Matt Borges Davinder Singh Chris Jobson

Milton Chandradas Midhun VP Wolfgang Scheer

Raca Jha

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 2


Disclaimer

The information in this presentation is confidential and proprietary to SAP and may not be disclosed without the permission of
SAP. Except for your obligation to protect confidential information, this presentation is not subject to your license agreement or
any other service or subscription agreement with SAP. SAP has no obligation to pursue any course of business outlined in this
presentation or any related document, or to develop or release any functionality mentioned therein.

This presentation, or any related document and SAP's strategy and possible future developments, products and or platforms
directions and functionality are all subject to change and may be changed by SAP at any time for any reason without notice.
The information in this presentation is not a commitment, promise or legal obligation to deliver any material, code or functionality.
This presentation is provided without a warranty of any kind, either express or implied, including but not limited to, the implied
warranties of merchantability, fitness for a particular purpose, or non-infringement. This presentation is for informational
purposes and may not be incorporated into a contract. SAP assumes no responsibility for errors or omissions in this
presentation, except if such damages were caused by SAPs intentional or gross negligence.

All forward-looking statements are subject to various risks and uncertainties that could cause actual results to differ materially
from expectations. Readers are cautioned not to place undue reliance on these forward-looking statements, which speak only
as of their dates, and they should not be relied upon in making purchasing decisions.

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 3


Agenda

Optimizing OData Services


Client side paging
Server side paging
Delta Tokens At request time
Delta Tokens At modification time
Client Application Development using the Mobile SDK
Overview
Preparation Initial app setup
Exercise 1, 2 Offline relationship without $expand
Exercise 3, 4 Reading data using paging
Exercise 5, 6, 7 Updating entities without constructing URLs
Exercise 8 Creating relationships without deep inserts

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 4


Optimizing OData Services

Measure OData size and time


Client side paging
Server side paging
Delta token
Calculate delta at request time
Calculate delta at modification time

Public
Avoid OData Services Overload
Understand how your OData service performs

How is my OData service


performing?
Measure the OData message size
and response time
Built-in browser development
tools

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 6


Client side paging
$skip and $top tokens

Products Entityset

1000 rows

1000 rows HTTP response1: Top 1000 rows skipping 1000 rows

HTTP response2: Top 1000 rows skipping 2000 rows


500 rows Since there are only 500 rows, 500 rows are returned

HTTP request1: Products?$skip=1000&top=1000


HTTP request2: Products?$skip=2000&top=1000

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 7


Client side paging
$skip and $top tokens

Pros:
Reduces size of the payload
Improves performance

Cons:
Client driven and is not controlled by the backend
Possibility of timeout issues, if client requests large number of rows

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 8


Server side paging
$skiptoken

Products Entityset

HTTP response1: Top 1000 rows


1000 rows
<link rel=next href=Products?$skiptoken=1000/>

HTTP response2: Top 1000 rows skipping 1000 rows


1000 rows
<link rel=next href=Products?$skiptoken=2000/>

500 rows

HTTP request1: Products


HTTP request2: Products?$skiptoken=1000

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 9


Server side paging
$skiptoken

Pros:
Reduces size of the payload
Improves performance
Controlled on the server side
Minimize timeout issues

Cons:
Client forced to make multiple calls to retrieve entire dataset

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 10


Delta token
What is delta token and how does it work

Products Entityset

HTTP response1: Initial request. All rows are returned


2000 rows
<link rel=delta href=Products?!deltatoken=201608050830/>

Modified HTTP response1: Modified rows after 201608050830 are returned


rows <link rel=delta href=Products?!deltatoken=201608050945/>
HTTP request1: Products
HTTP request2: Products?!deltatoken=201608050830

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 11


Delta token
2 main approaches

Delta token can be implemented in several ways


Can be grouped into 2 main approaches

1. Calculate Delta at request time


System compares old and new state to find modified records at request time
2. Calculate Delta at modification time
Based on Syclo Exchange Framework
ABAP system tracks modification when they occur

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 12


Delta token
delta at request time

Products Entityset

HTTP response1: Initial request. All rows are returned


2000 rows
<link rel=delta href=Products?!deltatoken=201608050830/>

HTTP request1: Products

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 13


Delta token
delta at request time

Products Entityset

Entire contents of Products retrieved and stored in local variable


2000 rows
System compares each entry to find if its modified
Modified entries are exported and sent as response
New delta token is created and sent along with response

Modified
rows

HTTP request2: Products?!deltatoken=201608050830

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 14


Delta token
delta at request time

Pros:
Implementation effort is rather small
Effective for comparatively small tables
Easier to debug and test
Reduces size of the payload

Cons:
Does not optimize performance of the backend
Response time for large entitysets are higher

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 15


Delta token
delta at modification time

Products Entityset

HTTP response1: Initial request. All rows are returned


2000 rows
<link rel=delta href=Products?!deltatoken=201608050830/>

HTTP request1: Products

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 16


Delta token
delta at modification time

Products Entityset Exchange Table

Key 1 Modified time Action C (for CREATE)

Key 2 Modified time Action U (for UPDATE)


2000 rows Key 3 Modified time Action D (for DELETE)

CREATE new
row

UPDATE row

DELETE row

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 17


Delta token
delta at modification time

Products Entityset Exchange Table


Entries in Exchange table are retrieved based
on timestamp
Keys Actions
Loop through each entry
Check if entry is CREATED, UPDATED or DELETED
2000 rows If action is C or U, add to response dataset
If action is D, add to deleted entities
New delta token is created and sent along with
response
Modified
rows

HTTP request2: Products?!deltatoken=201608050830

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 18


Delta token
delta at modification time

Pros:
Optimizes performance of the backend
More scalable
Reduces size of the payload

Cons:
Implementation effort is slightly more complex

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 19


Client application development

Initial app setup


Offline relationship without $expand
Reading data using paging
Updating entities without constructing URLs
Creating relationships without deep inserts

Public
Overview

Create an Offline OData application that:

Allows navigating relationships while offline

Uses OData server-provided deltas

Uses the sharing feature

Pages local reads

Allows creating new entities and relationships


while offline

Allows updating both server downloaded and new


entities while offline.

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 21


Preparation

Initial app setup

Public
Offline relationships without $expand

Use case
The app needs relationships while offline
To improve refresh performance, the use of OData server-provided deltas is desirable
To reduce load on the OData server, use of the sharing feature is desirable
Shared data should be related to non-shared data

Problems
OData V2 does not support deltas when $expand are used
Shared and non-shared data need to be separated in the defining requests

Solution
Expose referential constraints for the Associations in the $metadata and separate the defining requests

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 23


Exercise 1, 2

Offline relationship without $expand

Public
Reading data in pages

Use case
The app needs to display the data to the end user

Problems
The device can only display a limited amount of data at one time
Loading all entities into memory is not feasible

Solution
Use paging
The app can use client driven paging ($top and $skip) or server driven paging

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 25


Exercise 3, 4

Reading data using paging

Public
Updating entities without constructing URLs

Use case
The app needs to have the ability to modify and create new entities
Keys are generated by the OData server for new entities
While offline, both newly created entities and entities downloaded from the server need to be updated

Problem
Keys for locally created entities will be generated and therefore cannot be constructed by the app

Solution
OData is a hypermedia driven protocol
Use the links returned by the OData server (for all entities) rather than constructing URLs

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 27


Exercise 5, 6, 7

Updating entities without constructing URLs

Public
Creating relationships without deep inserts

Use case
The app needs to create multiple related new entities while offline
The involved relationships have a to many end

Problem
Offline OData does not support deep insert operations when at least one end of the relationships is to many

Solution
Use Content-ID referencing in a batch request

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 29


Exercise 8

Creating relationships without deep inserts

Public
Appendix

Delta token + $skiptoken

Public
Using delta token and $skiptoken together
Introducing soft state

Products Entityset Soft state (persist data in user specific session)


Why do we need to persist data in user specific session ?
Table content can get modified before user gets the entire initial data
1000 rows 1000 rows

Steps involved:
1. Obtain entire table content and delta token as a snapshot
1000 rows 1000 rows
2. Keep entire table content and delta token in soft state session
Until the delta token is sent
3. Split table data with $skiptoken last chunk contains delta token
500 rows 500 rows
HTTP response1: Top 1000 rows from soft state
HTTP request1: Products
<link rel=next href=Products?$skiptoken=1000/>

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 32


Server side paging
$skiptoken

Soft state (persist data in user specific session)

1000 rows

HTTP response2: Top 1000 rows skipping 1000 rows from soft state
1000 rows
<link rel=next href=Products?$skiptoken=2000/>

HTTP response3: Top 1000 rows skipping 2000 rows from soft state
500 rows
<link rel=delta href=Products?!deltatoken=201608050830/>
HTTP request2: Products?$skiptoken=1000
HTTP request3: Products?$skiptoken=2000

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 33


SAP TechEd Online

Continue your SAP TechEd


education after the event!
Access replays of
Keynotes
Demo Jam
SAP TechEd live interviews
Select lecture sessions
Hands-on sessions

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 34


Further information

Related SAP TechEd sessions:


MOB101 - SAP and Apple: Revolutionize the Mobile Work Experience
MOB102 - Next Stop: Enterprise Mobility in the Cloud
MOB161 - Hands-on-Bootcamp: Putting the enterprise in your mobile App
MOB200 - Going Digital: SAP Mobile Technology Strategy and Roadmap
MOB201 - Digitizing the Customer Experience: Considerations for B2C Mobile Solutions
MOB260 Data to Go: Learn to implement Offline in Mobile Apps
MOB307 - Extend SAP Fiori apps with the Mobile Services Integration Framework
MOB308 - Mobile DevOps: Continuous Integration on SAP HANA Cloud Platform

SAP Public Web


http://scn.sap.com/community/mobile
http://go.sap.com/product/technology-platform/mobile-app-development-platform.html
http://service.sap.com/roadmap

SAP Education and Certification Opportunities


www.sap.com/education

Watch SAP TechEd Online


www.sapteched.com/online

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 35


Feedback
Contact information:
Please complete your
Matt Borges
session evaluation for Senior Developer
matt.borges@sap.com
MOB260.

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 36


Thank you
Contact information:

matt.borges@sap.com
milton.chandradas@sap.com

Technology RIG

2015 SAP SE or an SAP affiliate company. All rights reserved.


2016 SAP SE or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://www.sap.com/corporate-en/about/legal/copyright/index.html for additional trademark information and notices.

Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.

In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SEs or its affiliated companies strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-
looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 38

You might also like