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 more SAP Netweaver Gateway OData 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 OData 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 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.
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.
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.
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.
Please feel free to comment and let us know your feedback. Subscribe for more updates
If you liked it, please share it! Thanks!