Skip to Content
0

How to delete all records in table with OData.remove method

May 30, 2017 at 07:43 PM

772

avatar image
Former Member

Hello,

I'm trying to remove all the records in a SAP HANA database table using OData version 2 on a SAP UI 5 application.

This is the method I am using : https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.odata.ODataModel.html#remove

I can delete a single record by specifying the index like so:

oDataModel.remove("/GMID_SHIP_TO_COUNTRY_STG(1)",

{

success: function(){},

error: function(){}

});

If I have one record in my table it will delete it. My questions is how can I easily delete all the data in my table? Do I have to use a batch operation or is there a way to select all entries to be deleted with the path itself?

Thanks.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Jun Wu May 31, 2017 at 12:46 AM
1

two ways:

1. create a function import, which delete all records

2.delete one by one, but they will be sent in batch as one request, so they are handled in backend as a whole.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thank you, I did not know it is handled as a batch by default.

0
Mahesh kumar palavalli May 31, 2017 at 07:09 AM
1

As you are using odata version v2, batch is enabled by default, you just have to loop the remove statement in loop and in the backend if the changeset is implemented, all the records can be accessed at one time.

Best Regards,e

Mahesh

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thank you for the help!

0
avatar image
Former Member May 31, 2017 at 10:15 AM
1

Loop through the record of table, Create a request body object, call submit changes FOR oData model.

EX.

// Get the model
var oModel = this.getOwnerComponent().getModel();
var mParameters = {};

//Get the request data in a object by looping table.
for (var i = 0; i < oTable.getSelectedIems().length; i++) {
var requestbody = {};
requestbody.tenant_id = operationData[i].TenantId;
requestbody.order_no = operationData[i].Aufnr;

// set group id with any name
mParameters.groupId = "deleteGroup";
oModel.remove("/Wworkorderoperation", requestbody, mParameters);
}
//set group id to deferred groups

oModel.setDeferredGroups(["deleteGroup"]);
oModel.submitChanges({
groupId: "deleteGroup",
success: function(oData) {

var successMsg = "All Data Deleted";
var bCompact = !!that.getView().$().closest(".sapUiSizeCompact").length;
MessageBox.success(successMsg, {
styleClass: bCompact ? "sapUiSizeCompact" : ""
});

},
error: function(oError) {
var oBody = oError.responseText,
    errorDetails = $(oBody).find("message ").text();

var bCompact = !!that.getView().$().closest(".sapUiSizeCompact").length;
MessageBox.error(errorDetails, {
styleClass: bCompact ? "sapUiSizeCompact" : ""
});

}
});


That's it.
Hope this works.




Regards
Shadan
Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanks for the help.

0