Search code examples
error-handlingodatasapui5

Handling OData Exceptions with Batch mode


I'm implementing SAPUI5 (Fiori like) application, that calls multiple CREATE operations in one batch. At now I've just redefined methods /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN / END and proper method is called multiple times. It is working fine when there is no errors.

How should I throw business exception in CREATE_ENTITY method to get message at ForntEnd layer? In console I can see only:

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
   <code>005056A509B11ED1B9BF9F46AA8E82ED</code>
   <message xml:lang="en">In the context of Data Services an unknown internal server error occured</message>
</error>

How to handle that?


Solution

  • I solved by myself.

    1. Redefine /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN and not implement any code. That will allow to call multiple operations (eg. _CREATE_ENTITY) in one batch.

    2. Implement _CREATE_ENTITY accordingly, make necessary checks and prepare data to be processed (create/ update), do not use COMMIT in that methods.

    3. Redefine /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_END and call all needed BAPI's or SQL INSERT / UPDATE statements. In case of any error throw /IWBEP/CX_MGW_BUSI_EXCEPTION - it will be handled properly on Front End. COMMIT will be called automatically.