首页 > SAP > ABAP > Create data in Backend using OData Service
2019
08-29

Create data in Backend using OData Service

In our last tutorial Update data in Back-end using OData service you have update the data which is already existed in back-end. For SAP Netweaver Gateway tutorial click here. In this tutorial we will create new data in back-end system. We are going to use a different service from our earlier tutorials. We are going to create material in back-end system. Before creating you have created a service in service builder which will get the Product List and Product Detail.

1. Go to Service Builder SEGW. Open the project in which you want to implement CREATE operation.

2. Before going further make sure you have implement GetEntitySet and GetEntity methods in the service to get List of Material and details of a single material. if you are not please go through these tutorials sap netweaver gateway tutorials.

3. Now expand Service Implementation node and select and right click on “Create” then after choose Go To Workbench.

4. You will be navigated to DPC Extension class. Put the class in change mode and from the list of methods choose PRODUCTSET_CREATE_ENTITY method and redefine it.

5. Write the below code in the method.


>> Source Code

METHOD productset_create_entity.

DATA: lwa_headerdata TYPE bapi_epm_product_header,
lwa_product    LIKE er_entity,
lt_return     TYPE STANDARD TABLE OF bapiret2.

*1.Get new data from service
io_data_provider->read_entry_data( IMPORTING es_data = lwa_product ).

lwa_headerdata–product_id = lwa_product–product_id.
lwa_headerdata–category = lwa_product–category.
lwa_headerdata–name = lwa_product–name.
lwa_headerdata–supplier_id = lwa_product–supplier_id.
lwa_headerdata–measure_unit = ‘EA’.
lwa_headerdata–currency_code = ‘EUR’.
lwa_headerdata–tax_tarif_code = ‘1’.
lwa_headerdata–type_code = ‘AD’.

*2.Call BAPI to create material
CALL FUNCTION ‘BAPI_EPM_PRODUCT_CREATE’
EXPORTING
headerdata               = lwa_headerdata
TABLES
return                   = lt_return.
IF lt_return IS INITIAL.
*3.If no errors in creattion, pass back the data
er_entity = lwa_product.
ENDIF.
ENDMETHOD.

<< Source Code


6. Activate the DPC Extension class an methods. We have implemented the method.Lets test whether our service creates material in back end system or not.

7. To test the service got SAP Netweaver Gateway Client.CREATE operation needs an full and proper HTTP instead manually adding the HTTP body lets copy it from the result of GetEntity(Read) methods. First call any single material by using the below URI to get the HTTP body.

/sap/opu/odata/SAP/ZSL_EPM_DEMO1_SRV/ProductSet(‘AD-1000’)

8. Once you have received the result.Click on Use as Request to copy the HTTP body to left panel in gateway client.

9. Once the HTTP body is copied and provide the material details to be created and change the HTTP request method from GET to POST and execute the service with below URI.

/sap/opu/odata/SAP/ZSL_EPM_DEMO1_SRV/ProductSet

10. You should get the repose 201-发料到成本中心 if the material is created in back-end.

11. To test that, you can again retrieve the data using the below URI adding the Product ID to the service and execute.

/sap/opu/odata/SAP/ZSL_EPM_DEMO1_SRV/ProductSet(‘AD-2001’)

最后编辑:
作者:yangsen
本站为个人博客网站,全由我个人维护,我从事SAP开发13年,其它ERP开发7年,基本都是零售行业。本站记录工作学习的过程, 有SAP相关询问专、兼职工作可随时联系我。 有网站相关的问题可直接在文章下方留言,或者联系我。 邮件:yan252@163.com给我。 QQ:415402519