Search code examples
sapui5

SAPUI5 batch submit returns error


I am using the following code, in an attempt to batch upload the changes made on a table:

onConfirmActionPressed: function() {
    var oModel = this.getModel();

    oModel.setUseBatch(true);

    oModel.submitChanges();
}

I am using setProperty() to set the new values, like this:

onSingleSwitchChange: function(oControlEvent) {
    var oModel = this.getView().getModel();
    var rowBindingContext = oControlEvent.getSource().getBindingContext();

    oModel.setProperty(rowBindingContext.sPath + "/Zlspr", "A");
}

When onConfirmActionPressed is executed, I get a server error, saying that "Commit work during changeset processing not allowed" on SAP R3.

When I upload the lines of the table one-by-one, it works fine. However, uploading this way is very slow, and in some cases it takes more than 10 minutes for the process to complete.

Am I doing something wrong while batch submitting? Is there a chance the issue is due to server (R3) misconfiguration?


Solution

  • You need to override methods: /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_END

    Keep track of the errors across all calls to update methods and if everything went OK then in changeset_end perform commit on the database


    edit:

    To clarify:

    In your Data Provider Class Extension in SAP Gateway you need to find your YOURENTITY_UPDATE_ENTITY method and get rid off any COMMIT WORK statements.

    Then you need to redefine /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN method and, which is a method which is fired before any batch operation. You could define a class attribute such as table mt_batch_errors which would be emptied in this method.

    When you post batch changes from UI5 using oModel.submitChanges() all single changes to Entities are directed to appropriate ..._UPDATE_ENTITY methods. You need to keep track of any possible errors and if any occurs then fill your mt_batch_errors table.

    After all entities have been updated /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_END method is fired in which you are able to check mt_batch_errors table if any errors occurred during the batch process. If there were errors then you should probably ROLLBACK WORK, and if not then you are free to COMMIT WORK.

    That is just an example of how it could be done, I'm curious of other suggestions.

    Good luck!