SAPUI5 oModel.create() - how to post data to the SAP backend?

∥☆過路亽.° 提交于 2019-12-01 01:14:20

Because there are only few threads on this topic at SO, which in my opinion do not answer the questions I had, I'll share my findings how to pass data to the backend via oModels create method:

First Define a type of your result entity (check your oData-Model to know the attributes, e.g. Name and YourID):

var oEntry = {};
oEntry.YourID = "0001";
oEntry.Name = "Peter";

Then fetch your model:

var oModel = sap.ui.getCore().getModel();

Then execute the create operation thanks to: https://sapui5.netweaver.ondemand.com/docs/api/symbols/sap.ui.model.odata.ODataModel.html

jQuery.sap.require("sap.ui.commons.MessageBox");
oModel.create('/EntitySet', oEntry, null, function(){
    sap.ui.commons.MessageBox.show(
         sap.ui.commons.MessageBox.alert("Success!");
     );
    },function(){
      sap.ui.commons.MessageBox.alert("Error!");
});

Results in Backend in Method "ENTITYSET_CREATE_ENTITY"-Method, where you can retrieve YourID and Name:

DATA: ls_data TYPE ycl_class_mpc=>ts_entity.

CALL METHOD io_data_provider->read_entry_data
  IMPORTING
    es_data = ls_data.

WRITE ls_data-name.
WRITE ls_data-yourid.

This example applies to single calls, you can see the result in ABAP is a structure. If you need to pass multiple datasets to the backend you should search for batch processing at https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.odata.ODataModel.html

Santhosh_Reddy

If you are still looking for a good blog on how to make a batch post then have a look at this post http://scn.sap.com/community/developer-center/front-end/blog/2012/11/18/gateway-batch-calls-from-sapui5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!