Since the editor didn't let me enter additional screen shots I am continuing my last blog post
OData service development with SAP Gateway - code-based service development - Part I in a new one: :wink:
Change Log
- 24.11.2016 - Moved ABAP Code to code boxes
Overview
We will continue our service implementation by implementing
- the GET_ENTITY method for the SalesOrderSet entity set and
- by implementing navigation to the items of a sales order
Provision the GET_ENTITY method of the service using ABAP code
- Open the Service Builder Project again
- Expand the node Service Implementation and SalesOrderSet and choose the entry
GetEntity (Read).
Now right-click on
GetEntity (Read) and choose
Go to ABAP Workbench.
- Confirm the warning“Operation SALESORDERSET_GET_ENTITY has not yet been implemented”
- Switch to edit mode, scroll down to the method SALESORDERSET_GET_ENTITY and make sure to select it.Click on the Redefine Method button.
Please note that the method SALESORDERSET_GET_ENTITYSET has already been redefined and therefore appears in black color.
- Use Cut&Paste to copy the entire coding into the ABAP editor.Replace ‘<XX>’ by your group numberThe code first calls the method io_tech_request_context->get_converted_keys.
The retrieved key value is used to select a single entry which is stored in the return structure er_entityof the method.
method salesorderset_get_entity.
data: lt_keys type /iwbep/t_mgw_tech_pairs,
ls_key type /iwbep/s_mgw_tech_pair,
ls_bp_key type zcl_ze2e100_xx_mpc=>ts_salesorder-salesorder,
ls_headerdata type zcl_ze2e100_xx_mpc=>ts_salesorder.
call method io_tech_request_context->get_converted_keys
importing
es_key_values = ls_headerdata.
ls_bp_key = ls_headerdata-salesorder.
select single *
into corresponding fields of @er_entity
from sepm_i_salesorder_e
where salesorder = @ls_headerdata-salesorder.
endmethod.
Add an additional entity set for Sales Order Items
- Open the Service Builder Project again
- We will now create a second entity type for sales order items and entity set.Right-click again on Data Model and select Import --> DDIC Structure.
- In the first step of the wizard provide:In the field Name, enter SalesOrderItem.
In the field ABAP Structure, enter SEPM_ISOIE.
Click Next.
- In the second step of the wizard provide:Select the checkbox for SEPM_ISOIE.
Deselect the checkbox for MANDT,Click Next.
- In the third screen of the wizard:
Select the checkbox Is Key for the fields SALESORDER and SALESORDERITEM.
Click Finish.
Add an association and navigation properties
- Expand Data Model and Right-click on Association and select Create
- In the first step of the wizard provide:Association Name
Assoc_SalesOrder_SalesOrderItem
Principal Entity
Entity Type Name
SalesOrder
Cardinality
1
Leave the checkbox Create related Navigation Property checked
Enter ToItems in the field Navigation Property
Dependent Entity
Entity Type Name
SalesOrderItem
Cardinality
1..n
Select the checkbox Create related Navigation Property checked
Enter ToSalesOrder in the field Navigation Property
- Click Next
- In the second step of the wizard in the field Dependent Property, enter SalesOrder by using the value help.
Click Next
- In the third step of the wizard press Finish.
- Press the Check Project Consistency button.
- Verify that no errors were found.
- Press Generate Runtime Objects
Provision the GET_ENTITY_SET method of the entity set SalesOrderItemSet
- Open the Service Builder Project again
- Expand the node Service Implementation and SalesOrderItemSet and choose the entry GetEntitySet (Query).
Now right-click on GetEntitySet (Query) and choose Go to ABAP Workbench.
- Confirm the warning“Operation SALESORDERITEMSE_GET_ENTITYSET has not yet been implemented”
- Switch to edit mode, scroll down to the method SALESORDERITEMSE_GET_ENTITYSET and make sure to select it.Click on the Redefine Method button.
method salesorderitemse_get_entityset.
data: lt_nav_path type /iwbep/t_mgw_tech_navi,
ls_nav_path type /iwbep/s_mgw_tech_navi,
lt_keys type /iwbep/t_mgw_tech_pairs,
ls_key type /iwbep/s_mgw_tech_pair,
ls_so_key type zcl_ze2e100_xx_mpc=>ts_salesorder-salesorder,
ls_headerdata type zcl_ze2e100_xx_mpc=>ts_salesorder.
data: lv_osql_where_clause type string.
lt_nav_path = io_tech_request_context->get_navigation_path( ).
read table lt_nav_path into ls_nav_path with key nav_prop = 'TOITEMS'.
if sy-subrc = 0.
call method io_tech_request_context->get_converted_source_keys
importing
es_key_values = ls_headerdata.
ls_so_key = ls_headerdata-salesorder.
select * from sepm_i_salesorderitem_e
into corresponding fields of table @et_entityset
where salesorder = @ls_so_key.
else.
lv_osql_where_clause = io_tech_request_context->get_osql_where_clause_convert( ).
select * from sepm_i_salesorderitem_e
into corresponding fields of table @et_entityset
where (lv_osql_where_clause).
endif.
endmethod.
- Click on Activate
- Confirm the Activation popup
- Navigate back to the Service Builder main screen using the back button multiple times.
- In the navigation tree right-click on GW_HUB and select SAP Gateway Client.Alternatively click on the SAP Gateway Client button in the detail section.
If you now want to annotate this service so that you are able to use the list report template from SAP Web IDE please check out my following blog:
https://blogs.sap.com/2017/04/21/how-to-add-annotations-to-an-odata-service-using-code-based-impleme...