Skip to Content
avatar image
Former Member

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


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 :

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



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?


Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    May 31, 2017 at 12:46 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • May 31, 2017 at 07:09 AM

    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


    Add comment
    10|10000 characters needed characters exceeded

  • May 31, 2017 at 10:15 AM

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


    // 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
    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.
    Add comment
    10|10000 characters needed characters exceeded