Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
Showing results for 
Search instead for 
Did you mean: 

In the first article we looked at what Delta Queries were and the use cases that it addresses. Now we will look at the mechanics of doing a delta query call and what the requests and responses will look like.


As we mentioned at the start a typical OData collection that is delta query enabled returns the same content as the query would do if it were not the only difference is that at the end of the document there is a link element. Well actually we don't have to imagine, the latest Netweaver Gateway with Service Pack 7 has these services already installed to consume


For now we are going to assume however we have a TravelAgencies collection that is delta query enabled (TravelAgencies_DQ) and we have made the first GET so we have the data parsed and cached locally in for example HTML5 LocalStorage (or IndexDB).


The link element looks like the following:

<link rel="delta" href="TravelAgencies_DQ?!deltatoken='12313D220A3A1EE3AA8A133BE813AF0F_20140310123632'"/>


If we now make a call to the server with the delta token we will get back an empty feed which is what we expect since we have not modified anything in the collection.


What we can do now is create a new travel agency using the standard OData CRUD pattern of a POST request and we will get back a 201 created http response.



<my service root>/TravelAgencies_DQ






Content-Type: application/json




"agencynum": "04051971",

"NAME": "Great Escapades",

"STREET": "10 Square Bristol",


"CITY": "Bristol",


"TELEPHONE":"+44 117 3153966",

"URL": "",

"LANGU": "E",




The response back is:

201 - created


Now comes the interesting part:

We do a query: <My server>/TravelAgencies_DQ?!deltatoken='12313D220A3A1EE3AA8A133BE813AF0F_20140310123632' and we get back the newly created entity only rather than the entire collection:





     xmlns:d=""   xml:base="<my service root>">


  <id><my service root>/TravelAgencies_DQ</id>

  <title type="text">TravelAgencies_DQ</title>





  <link href="TravelAgencies_DQ" rel="self" title="TravelAgencies_DQ"/>



    <id><my service root>/TravelAgencies_DQ('04051971')</id>

    <title type="text">TravelAgencies_DQ('04051971')</title>


    <category term="RMTSAMPLEFLIGHT.Travelagency_DQ" scheme=""/>

    <link href="TravelAgencies_DQ('04051971')" rel="edit" title="Travelagency_DQ"/>

    <content type="application/xml">





        <d:NAME>Great Escapades</d:NAME>

        <d:STREET>10 Square Bristol</d:STREET>


        <d:POSTCODE>BS1 4NT</d:POSTCODE>




        <d:TELEPHONE>+44 117 3153966</d:TELEPHONE>









  <link rel="delta" href="TravelAgencies_DQ?!deltatoken='12313D220A3A1EE3AA8A133BE813AF0F_20140310130010'"/>



As can be seen above, we also have a new key, which we can then recognize as a new record in the local cache and add it to the cache as such.


Now finally calling the collection again with the delta token returned from the last query returns back an empty feed as expected since we have got all the changes already.





    xmlns:d="" xml:base="<my service root>">

    <id><my service root>/TravelAgencies_DQ</id>

    <title type="text">TravelAgencies_DQ</title>





    <link href="TravelAgencies_DQ" rel="self" title="TravelAgencies_DQ"/>

    <link rel="delta" href="TravelAgencies_DQ?!deltatoken='12313D220A3A1EE3AA8A133BE813AF0F_20140310130901'"/>



So this is how adding records is done in a delta query as well as showing how to create a record using just plain JSON which is far easier and clearer than with XML.


Of course building a synchronization system would be much more difficult if we did have a mechanism to support detecting deletes. Detecting inserts and updates in a system is a trivial problem but when delete is also required, that is more of a challenge.

  • SAP Managed Tags: