Presentation
The OData service that has been created in the initial segment of this blog is perused as it were. In the second piece of the blog OData service development with SAP Gateway using CDS via Referenced Data Sources I might want to demonstrate the way that we can make the portrayal of the deals request updatable.
This will show
- how basic updates can be carried out and specifically
- how this should be possible for Texts that are gotten to by the SADL system by means of a join and the comment @ObjectModel.text.association: ‘_Text’.
Change history
- 17.06.2016 – Fixed a grammatical error that the Characterize strategy is situated in the DPC_EXT class as opposed to in the MPC_EXT class
- 24.11.2016 – Moved code tests to code boxes to keep away from issues with reorder
- 05.05.2017 – Added data how to deal with etags for updates and how to carry out a capability import
Service Implementation
- Open the Help Manufacturer project ZE2E100__2 again that has been fabricated in view of the blog referenced previously.
- Grow the organizer Runtime curios and right-click on ZZCL_ZE2E100_XX_2_DPC_EXT and pick the passage Go To ABAP Workbench.
- Change to alter mode, look down to the strategy ZSEPM_C_SALESORD_UPDATE_ENTITY and make a point to choose it and snap on the Rethink Technique button.
- Reorder the coding into the Update strategy
method zsepm_c_salesord_update_entity.
data: lt_keys type /iwbep/t_mgw_tech_pairs,
ls_key type /iwbep/s_mgw_tech_pair,
ls_so_id type bapi_epm_so_id,
ls_headerdata_update type bapi_epm_so_header,
ls_headerdatax type bapi_epm_so_headerx,
ls_headerdata_key type zcl_ze2e100_xx_2_mpc=>ts_zsepm_c_salesorder_tpltype,
ls_headerdata_payload type zcl_ze2e100_xx_2_mpc=>ts_zsepm_c_salesorder_tpltype,
lt_return type table of bapiret2,
ls_return type bapiret2,
err_msg type string,
ls_message type scx_t100key.
call method io_tech_request_context->get_converted_keys
importing
es_key_values = ls_headerdata_key.
io_data_provider->read_entry_data( importing es_data = ls_headerdata_payload ).
ls_so_id-so_id = ls_headerdata_key-salesorder.
" Product header data (non-key) fields that can be updated
" via the BAPI are marked with an 'X'
ls_headerdatax-so_id = ls_headerdata_key-salesorder.
ls_headerdatax-note = 'X'.
" move content of the fields that should be
" updated from payload to the corresponding
" field of the BAPI
move ls_headerdata_key-salesorder to ls_headerdata_update-so_id.
move ls_headerdata_payload-t_salesorder to ls_headerdata_update-note.
call function 'BAPI_EPM_SO_CHANGE'
exporting
so_id = ls_so_id " EPM: SO Id
soheaderdata = ls_headerdata_update " EPM: so header data of BOR object
soheaderdatax = ls_headerdatax
tables
return = lt_return. " Return Parameter
if lt_return is not initial.
loop at lt_return into ls_return.
err_msg = ls_return-message .
endloop.
ls_message-msgid = 'SY'.
ls_message-msgno = '002'.
ls_message-attr1 = err_msg.
raise exception type /iwbep/cx_mgw_busi_exception
exporting
textid = ls_message.
endif.
endmethod.
Data: The supplanted coding above recovers the substance of the properties of the approaching solicitation.
Since various DDIC structures are utilized by the substance type and the BAPI that is utilized to refresh the deals request the approaching fields are moved to the information structure utilized by the BAPI.
To make the SAP Web IDE CUD Expert Detail Format mindful that the property SalesOrder_Text is presently updatatable we need to comment on the property utilizing the annoation sap:updatable=true.In this exceptional case this isn’t possible in the Cds view. So we need to utilize the choice to add extra metadata by carrying out the Characterize technique in the model supplier expansion class.
Extend the envelope Runtime antiquities and right-click on ZZCL_ZE2E100_XX_2_MPC_EXT and pick the section Go To ABAP Workbench.
Reorder the accompanying coding into the Characterize technique.
method define.
data:
lo_entity_type type ref to /iwbep/if_mgw_odata_entity_typ,
lo_property type ref to /iwbep/if_mgw_odata_property.
call method super->define( ).
lo_entity_type = model->get_entity_type( iv_entity_name = 'Zsepm_C_Salesorder_TplType').
lo_property = lo_entity_type->get_property( iv_property_name = 'SalesOrder_Text').
lo_property->set_updatable( abap_true ).
endmethod.
Click on Enact.
Affirm the enactment popup.
Since the update strategy is currently executed you can now test your administration. This should be possible by the underlying REST client, the SAP Entryway Client which I can truly suggest.
After you have tried the assistance effectively utilizing the SAP Passage Client you can utilize SAP Web IDE to produce an application in light of the Expert Detail CUD format.
Test the service using the SAP Gateway Client
Explore back to the Help Developer by squeezing the “Back-Button” a few times
In the route tree right-click on GW_HUB and select SAP Door Client.Alternatively start the SAP Entryway Client in a different window by beginning exchange/n/IWFND/GW_CLIENTIf we presently test the update utilizing the SAP Passage Client this ought to turn out great.
Enter the accompanying URI/sap/opu/odata/SAP/ZE2E100_XX_2_SRV/Zsepm_C_Salesorder_Tpl(‘5000000’)After squeezing Execute button you see a solitary deals order.Replace ” with your gathering name
Press the Utilization as Solicitation button to make a legitimate http demand body.
Change the substance of the field SalesOrder_Text for instance to ‘Test Update Text’.
Change the http technique from GET to PUT.
Press Execute
- As a result you get an empty http response with the return code 204.
- Presently again play out a GET solicitation to confirm that the information has been changed
- Enter the accompanying URI
- /sap/opu/odata/SAP/ZE2E100_XX_2_SRV/Zsepm_C_Salesorder_Tpl(‘5000000’)
- In the wake of squeezing Execute button you see a solitary deals request with the changed text.
- Supplant ” with your gathering name
Testing the service with SAP Web IDE
While making an application in light of the Muck Q Expert Detail layout you will actually want to fabricate an application that permits you to refresh deals orders as displayed in the accompanying screen shot.
ENJOY MORE RELATED BLOGS
Part 3: Creating and Querying O DATA Services (Read Blog)