Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Hello everyone,

I was trying to implement batch processing in oData v2 and noticed very few documents available describing the process. Most of the articles on internet are copied from other sources. Batch processing stands for processing multiple records in one go.

I finished the implementation in SAPUI5 as well as in Gateway Service. I will try to explain this process in this post.


In this example, the version of sap-ui-core library is set to 1.54.6. Please find following code block that you have to set in Controller.
var tmpModel = new ODataModel("<your_service>_SRV/", true);
this.getView().setModel(tmpModel, "tmpModel");
var mParameters = {groupId:"foo",success:function(odata, resp){ console.log(resp); },error: function(odata, resp) { console.log(resp); }};

for(var m=0; m<oPayload.length; m++) {
tmpModel.update("/YOUR_ENTITYSet(Key1='Valu1',Key2='Value2')", oPayload[m], mParameters);

First, we have to define an oData model with a service URL and set its default Binding mode to TwoWay. Since we are going to send payload to Gateway server in a batch, we set the parameter value as true of a function setUseBatch associated with oDataModel. The fundamental idea is to first prepare requests by looping over Items of your table or list, attach it to a batch using groupId and fire.

Next, we attach the defined model to application's view and set the deferred group to 'foo'.

To perform actual interactions with oData service, we have commonly used methods associated with every model such as read(), create(), update(), delete() etc. In this example, I am updating the values from a table hence using tmpModel.update().

In third parameter of method update(), we have to pass an object with a property as groupId. This will not fire any request immediately but keeps them in a stack. Its value must match with the deferred group that we have set earlier i.e. foo. To read more about parameters, please go through oData Model methods documentation.

One important point here to note is that there must be no spaces in the values set for a key. It means it could be 'Value1' or '%20%20Value1' but not '  Value1'. A space here would result as a Bad request response in Gateway Builder.

We can see this result from t-code /IWFND/ERROR_LOG. Select a line from Overview table => Click Replay button => Select SAP Gateway Client.

From Backend server where oData service resides, its about redefining 2 methods from DPC_EXT class of service.

First open the class using SE24 t-code, then under left pane find following methods, right click on them and select redefine.




We do not have to write anything in them. For tmpModel.update(), set a breakpoint in UPDATE_ENTITY method of your class.

Number of times UPDATE ENTITY will execute = Number of iterations we have in for loop.

We can also have a callback execution attached to a batch request. This we have to pass in mParameters object. The SAPUI5 code block is self explanatory.

And here comes the end of the document.




Labels in this area