Business Example
You are a developer or solution architect in your company. You need to model and implement navigation between entities.
- Template:
- GW100_S_DECLMODEL (SAP Gateway Project)
- Solution:
- GW100_S_NAVIGATION (SAP Gateway Project)
Note
This exercise requires an SAP Learning system. Login information are provided by your system setup guide.Note
You may continue with your solution of the previous exercise or copy the template to ZGW100_##_NAVIGATION. Whenever the values or object names in this exercise include ##, replace ## with the number of your user.Prerequisites
The data model for business partner was defined in exercise Add an Additional Entity to a Data Model and the query operation for products was implemented in exercise Implement a Query Operation.
Task 1: Model a Navigation using the SAP Gateway Service Builder
Steps
In the SAP Gateway Service Builder of your SAP S/4HANA (S4H) system, model a navigation between the BusinessPartner and Product entities connecting one BusinessPartnerID to many SupplierID. Create the navigation property ProductSet in the BusinessPartner entity type.
In the SAP Easy Access of your S4H, search for SAP Gateway Service Builder or start transaction SEGW.
In the SAP Gateway Service Builder, for your project, expand the node Data Model.
In the context menu of Associations, choose Create.
In the Create Association popup, in the Association Name field, enter BusinessPartner_Products.
For the Principal Entity, enter the following values:
Field | Value |
---|
Entity Type Name | BusinessPartner |
Cardinality | 1 |
Navigation Property | ProductSet |
For the Dependent Entity, enter the following values:
Field | Value |
---|
Entity Type Name | Product |
Cardinality | 1..n |
Choose Next.
In the Dependent Property field, using the value help, enter SupplierID and choose Next.
Choose Finish.
Choose Generate Runtime Objects.
In the SAP Gateway Client of your S4H, compare the result of the $metadata request with the Data Model of your SAP Gateway project.
In the SAP Gateway Service Builder of your S4H, double-click Service Maintenance.
Choose SAP Gateway Client.
In the SAP Gateway Client, select HTTPS as Protocol.
Choose Add URI Option.
In the Add URI Option popup, double-click $metadata.
Example
/sap/opu/odata/SAP/ZGW100_##_STUDENT_SRV/$metadata
Choose Execute.
Result
The HTTP Response displays the metadata of your service.
Compare the service metadata with the Data Model of your SAP Gateway project.
Task 2: Implement and Test a Navigation
Steps
In the SAP Gateway Client of your S4H, test the navigation in your service. Query the products of a business partner.
In the SAP Gateway Client of your S4H, choose Entity Set.
In the Entity Sets popup, double-click BusinessPartnerSet.
Example
/sap/opu/odata/SAP/ZGW100_##_STUDENT_SRV/BusinessPartnerSet
Choose Execute.
Result
The HTTP Response displays all business partners.
In the Request URI field, add one of the links to the products of a business partner.
Example
/sap/opu/odata/SAP/ZGW100_##_STUDENT_SRV/BusinessPartnerSet('0100000000')/ProductSet
Choose Execute.
Result
The HTTP Response displays all products for all business partners instead of only for the requested one.
In the SAP Gateway Service Builder of your S4H, adapt the method PRODUCTSET_GET_ENTITYSET to query products based on the navigation source using the selection criteria of BAPI_EPM_PRODUCT_GET_LIST function module.
In the SAP Gateway Service Builder of your S4H, expand Service Implementation → ProductSet.
In the context menu of GetEntitySet (Query), choose Go to ABAP Workbench.
Add the following code or copy it from the solution:
Note
If you copy the code from the solution, replace the references to the model provider class of the solution with one to your model provider class.12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
METHOD productset_get_entityset.
DATA: lt_headerdata TYPE TABLE OF bapi_epm_product_header,
lt_return TYPE TABLE OF bapiret2.
DATA: ls_bp_id TYPE bapi_epm_bp_id,
ls_bp_headerdata TYPE bapi_epm_bp_header,
lt_so_supplier TYPE TABLE OF
bapi_epm_supplier_name_range,
ls_businesspartner TYPE
zcl_zgw100_##_student_mpc=>ts_businesspartner.
* Get key for navigation source
CASE io_tech_request_context->get_source_entity_type_name( ).
WHEN zcl_zgw100_##_student_mpc=>gc_businesspartner.
io_tech_request_context->get_converted_source_keys(
IMPORTING
es_key_values = ls_businesspartner
).
ls_bp_id-bp_id = ls_businesspartner-businesspartnerid.
CALL FUNCTION 'BAPI_EPM_BP_GET_DETAIL'
EXPORTING
bp_id = ls_bp_id
IMPORTING
headerdata = ls_bp_headerdata
TABLES
return = lt_return.
IF lt_return IS NOT INITIAL.
" Message Container
mo_context->get_message_container( )
->add_messages_from_bapi( lt_return ).
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
EXPORTING
textid = /iwbep/cx_mgw_busi_exception=>business_error
message_container = mo_context->get_message_container( ).
ENDIF.
lt_so_supplier = VALUE #( (
sign = 'I'
option = 'EQ'
low = ls_bp_headerdata-company_name ) ).
ENDCASE.
* Get data
CALL FUNCTION 'BAPI_EPM_PRODUCT_GET_LIST'
TABLES
headerdata = lt_headerdata
selparamsuppliernames = lt_so_supplier
return = lt_return.
...
ENDMETHOD.
Choose Activate.
In the Inactive Objects popup, select all objects and choose Continue.
In the SAP Gateway Client of your S4H, retest the navigation in your service. Query the products of a business partner.
In the SAP Gateway Client, choose Execute.
Example
/sap/opu/odata/SAP/ZGW100_##_STUDENT_SRV/BusinessPartnerSet('0100000000')/ProductSet
Result
The HTTP Response displays the products for the business partner.
Task 3: Implement and Test an Expand
Steps
In the SAP Gateway Client of your S4H, test the query option $expand in your service. Read a business partner including its products.
In the SAP Gateway Client of your S4H, replace the / in front of ProductSet with ?$expand=.
Example
/sap/opu/odata/SAP/ZGW100_##_STUDENT_SRV/BusinessPartnerSet('0100000000')?$expand=ProductSet
Choose Execute.
Result
The HTTP Response displays the error Method 'BUSINESSPARTNERS_GET_ENTITY' not implemented in data provider class.
In the SAP Gateway Service Builder of S4H, navigate to the implementation of the BUSINESSPARTNERS_GET_ENTITY method of your project.
In the SAP Gateway Service Builder of your S4H, for your project, expand the node Service Implementation → BusinessPartnerSet.
In the context menu of GetEntity (Read), choose Go to ABAP Workbench.
In the Information popup, choose Continue.
Result
The method is not yet implemented.
In the Class Builder, redefine the method BUSINESSPARTNERS_GET_ENTITY to read a single business partner by calling the BAPI_EPM_BP_GET_DETAIL function module.
In the Class Builder, choose Display <-> Change.
Place the curser in the method BUSINESSPARTNERS_GET_ENTITY and choose Redefine.
Write the following code or copy it from the solution:
12345678910111213141516171819202122232425262728293031323334353637383940414243
METHOD businesspartners_get_entity.
DATA: ls_bp_id TYPE bapi_epm_bp_id,
ls_headerdata TYPE bapi_epm_bp_header,
lt_return TYPE TABLE OF bapiret2.
* Get key fields from request
io_tech_request_context->get_converted_keys(
IMPORTING
es_key_values = er_entity
).
ls_bp_id-bp_id = er_entity-businesspartnerid.
* Get data
CALL FUNCTION 'BAPI_EPM_BP_GET_DETAIL'
EXPORTING
bp_id = ls_bp_id
IMPORTING
headerdata = ls_headerdata
TABLES
return = lt_return.
IF lt_return IS NOT INITIAL.
" Message Container
mo_context->get_message_container( )
->add_messages_from_bapi( lt_return ).
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
EXPORTING
textid = /iwbep/cx_mgw_busi_exception=>business_error
message_container = mo_context->get_message_container( ).
ENDIF.
* Map properties from the back-end to output response structure
er_entity = VALUE #(
businesspartnerid = ls_headerdata-bp_id
businesspartnerrole = ls_headerdata-bp_role
emailaddress = ls_headerdata-email_address
companyname = ls_headerdata-company_name
currencycode = ls_headerdata-currency_code
city = ls_headerdata-city
street = ls_headerdata-street
country = ls_headerdata-country
addresstype = ls_headerdata-address_type ).
ENDMETHOD.
Choose Activate.
In the Inactive Objects popup, select all objects and choose Continue.
In the SAP Gateway Client, retest the expand in your service. Read a business partner including its products.
In the SAP Gateway Client of your S4H, choose Execute.
Example
/sap/opu/odata/SAP/ZGW100_##_STUDENT_SRV/BusinessPartnerSet('0100000000')?$expand=ProductSet
Result
The HTTP Response displays the business partner and its products.