cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple rows update in backend.

amol_samte
Contributor
0 Kudos

Hi folks,

How to update multiple entries.. I have scenario like based on check box select I need to update those rows in back end through O data code based service.


If you can paste links too....


-Amol

Accepted Solutions (0)

Answers (2)

Answers (2)

omkar_patil5
Discoverer
0 Kudos

There is no such method as UPDATE_ENTITYSET in DPC_EXT you might find UPDATE_ENTITY but cannot be used for multiple record processing. However, you can achieve this using CHANGESET BEGIN, PROCESS & END Methods from DPC.

AbhishekSharma
Active Contributor
0 Kudos

Hi Amol,

For updating multiple entries into db table using SAPUI5 and Gateway you got method in Model called submitBatch.

Every row that you want to update you need to first retrieve that row and need to change values init and then need to put it back in Entity object.

This you need to do for all the rows which you will be getting based on Checkbox selection (assuming you are already getting functionality working).

So how to bundle this information and save it in onego:

For example you got columns from your Entry as FNM,LNM,ADDR.

your entity will look like as below:

info1={FNM:'aa',LNM:'bb','ADDR:'cc''}

info2={FNM:'aa1',LNM:'bb2','ADDR:'cc3''}


you got these two entity with updated values now we need to send this data to Gateway for save.

Now to send this full data we need to add this in an Array.


FULLDATA[];


FULLDATA.push(oModel.createBatchOperation("USERINFO", "<HTTP METHOD>", info1) );

FULLDATA.push(oModel.createBatchOperation("USERINFO", "<HTTP METHOD>", info2) );

<HTTP METHOD> we need to use eighter PUT or POST method.

now your data is available in FULLDATA array we just need to send it to Gateway Service.

now we will submit these changes:

oModel.addBatchChangeOperations(FULLDATA);

oModel.submitBatch(function(){alert('success');},function(){alert('failed');});

now in DPC_EXT method inside UPDATE_ENTITYSET you need to read this data and just call ABAP Modify statement.

Please have a look to below post

Thanks-

Abhishek




amol_samte
Contributor
0 Kudos

Hi Abhishek,

I am new to this subject.

1. Can you tell me where can i get SubmitBatch....

2. Other side in DPC_EXT can I get tabular data? I guess yes, then in which parameter?

3. Where do I need to write below code, in UI 5 App?


info1={FNM:'aa',LNM:'bb','ADDR:'cc''}

info2={FNM:'aa1',LNM:'bb2','ADDR:'cc3''}


you got these two entity with updated values now we need to send this data to Gateway for save.

Now to send this full data we need to add this in an Array.


FULLDATA[];


FULLDATA.push(oModel.createBatchOperation("USERINFO", "<HTTP METHOD>", info1) );

FULLDATA.push(oModel.createBatchOperation("USERINFO", "<HTTP METHOD>", info2) );

<HTTP METHOD> we need to use eighter PUT or POST method.

now your data is available in FULLDATA array we just need to send it to Gateway Service.

now we will submit these changes:

oModel.addBatchChangeOperations(FULLDATA);

oModel.submitBatch(function(){alert('success');},function(){alert('failed');})

-Amol

AbhishekSharma
Active Contributor
0 Kudos

Hi Amol,

submitBatch is a method of your model like below:

oModel.submitBatch() this you need to write in your view's controller.

Go through below link

JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.ODataModel

You need to write this code of making

For making data to send to Service you need to create object you can do this as below :

this aa,bb,cc are the values which you have taken from frontend in View as below:

// Reading values from frontend form as below

var aaVal = sap.ui.getCore().byId("FNM").getValue();

var bbVal = sap.ui.getCore().byId("LNM").getValue();

info1={FNM:aaVal ,LNM:bbVal}

info2={FNM:'aaVal1',LNM:'bbVal2'}

var FULLDATA= [];

// now pushing your data to object to send to Server

    FULLDATA.push( oModel.createBatchOperation("USERINFO", "PUT", info1) );

    FULLDATA.push( oModel.createBatchOperation("USERINFO", "PUT", info2) );

// Above you can use PUT or POST

<HTTP METHOD> we need to use eighter PUT or POST method.

now your data is available in FULLDATA array we just need to send it to Gateway Service.

now we will submit these changes:

oModel.addBatchChangeOperations(FULLDATA);

oModel.submitBatch(function() {

  sap.ui.commons.MessageBox.alert("Record Updated Successfully!", '', "Success");

}, function() {

  sap.ui.commons.MessageBox.alert("Record Update Error!", '', "Error");

});

oModel.refresh();

now in DPC_EXT method inside UPDATE_ENTITYSET you need to read this data and just call ABAP Modify statement. I can not recall exact table parameter but every EntitySet method is having Table parameter which contains all these values which you send to gateway from Frontend.

Thanks-

Abhishek