5 Segw
5 Segw
5 Segw
1
3) Create Entity Type
2
5)Expand it, Go to properties
Provide properties as
3
9)Go to tcode: /IWFND/MAINT_SERVICE , Click on Add service button and enter the below information
10) Select the Entry and click on ‘Add Selected Services’ button
Press Enter
11)Go to Tcode: /IWFND/MAINT_SERVICE and click on Filter button and Enter the below information
and Press Enter
4
12) Click on ‘SAP Gateway Client’ button
5
15) It Prompt us and information us
method PRODUCTSET_GET_ENTITYSET.
data:ls_headerdata type ZPRODUCTDETAILS,
lt_headerdata type TABLE OF ZPRODUCTDETAILS,
ls_product LIKE LINE OF ET_ENTITYSET.
6
SELECT PRODUCT_ID TYPE_CODE CATEGORY NAME DESCRIPTION
SUPPLIER_ID FROM ZPRODUCTDETAILS INTO CORRESPONDING FIELDS OF TABLE lt_header
data.
LOOP AT lt_headerdata INTO LS_HEADERDATA.
ls_product-PRODUCT_ID = LS_HEADERDATA-PRODUCT_ID.
ls_product-TYPE_CODE = LS_HEADERDATA-TYPE_CODE.
ls_product-CATEGORY = LS_HEADERDATA-CATEGORY.
ls_product-NAME = LS_HEADERDATA-NAME.
ls_product-DESCRIPTION = LS_HEADERDATA-DESCRIPTION.
ls_product-SUPPLIER_ID = LS_HEADERDATA-SUPPLIER_ID.
APPEND LS_PRODUCT TO ET_ENTITYSET.
ENDLOOP.
endmethod.
/sap/opu/odata/sap/ZPRODUCTDETAIL_SRV/ProductSet?$format=json
18)
7
USE CODE:
method PRODUCTSET_GET_ENTITY.
data:ls_key_tab TYPE /IWBEP/s_MGW_NAME_VALUE_PAIR,
LS_PRODUCT_ID TYPE ZPRODUCTDETAILS-PRODUCT_ID,
LS_HEADERDATA TYPE ZPRODUCTDETAILS.
loop at it_key_tab into ls_key_tab.
IF LS_KEY_TAB-NAME = 'PRODUCT_ID'.
LS_PRODUCT_ID = LS_KEY_TAB-VALUE.
ENDIF.
ENDLOOP.
SELECT SINGLE PRODUCT_ID TYPE_CODE CATEGORY NAME DESCRIPTION supplier_id
FROM ZPRODUCTDETAILS INTO CORRESPONDING FIELDS OF
LS_HEADERDATA WHERE PRODUCT_ID = LS_PRODUCT_ID.
8
ER_ENTITY-PRODUCT_ID = LS_HEADERDATA-PRODUCT_ID.
ER_ENTITY-TYPE_CODE = LS_HEADERDATA-TYPE_CODE.
ER_ENTITY-CATEGORY = LS_HEADERDATA-CATEGORY.
ER_ENTITY-NAME = LS_HEADERDATA-NAME.
ER_ENTITY-DESCRIPTION = LS_HEADERDATA-DESCRIPTION.
er_entity-supplier_id = ls_headerdata-supplier_id.
endmethod.
/sap/opu/odata/sap/ZPRODUCTDETAIL_SRV/ProductSet('HT-1000')?$format=xml
method PRODUCTSET_GET_ENTITYSET.
DATA: ls_headerdata TYPE zproductdetails,
lt_headerdata TYPE STANDARD TABLE OF zproductdetails,
ls_product LIKE LINE OF et_entityset.
DATA: ls_selparamproductid TYPE bapi_epm_product_id_range,
lt_selparamproductid TYPE STANDARD TABLE OF
bapi_epm_product_id_range,
ls_filter_select_options TYPE /iwbep/s_mgw_select_option,
ls_select_option TYPE /iwbep/s_cod_select_option.
LOOP AT it_filter_select_options INTO ls_filter_select_options.
IF ls_filter_select_options-property EQ 'PRODUCT_ID'.
LOOP AT ls_filter_select_options-select_options INTO
ls_select_option.
ls_selparamproductid-sign = ls_select_option-sign.
ls_selparamproductid-option = ls_select_option-option.
9
ls_selparamproductid-low = ls_select_option-low.
ls_selparamproductid-high = ls_select_option-high.
APPEND ls_selparamproductid TO lt_selparamproductid.
ENDLOOP.
ENDIF.
ENDLOOP.
SELECT product_id type_code category name description SUPPLIER_ID
FROM zproductdetails INTO CORRESPONDING FIELDS OF TABLE
lt_headerdata WHERE product_id IN lt_selparamproductid .
LOOP AT lt_headerdata INTO ls_headerdata.
ls_product-product_id = ls_headerdata-product_id.
ls_product-type_code = ls_headerdata-type_code.
ls_product-category = ls_headerdata-category.
ls_product-name = ls_headerdata-name.
ls_product-description = ls_headerdata-description.
ls_product-SUPPLIER_ID = ls_headerdata-SUPPLIER_ID.
APPEND ls_product TO et_entityset.
ENDLOOP.
endmethod.
URL
10
Regenerate the Project
Entity_set Code:
ls_product-supplier_id = ls_headerdata-supplier_id.
METHOD productset_get_entityset.
DATA: ls_headerdata TYPE zproductdetails,
lt_headerdata TYPE STANDARD TABLE OF zproductdetails,
ls_product LIKE LINE OF et_entityset.
DATA: ls_selparamproductid TYPE bapi_epm_product_id_range,
lt_selparamproductid TYPE STANDARD TABLE OF
bapi_epm_product_id_range,
ls_filter_select_options TYPE /iwbep/s_mgw_select_option,
ls_select_option TYPE /iwbep/s_cod_select_option.
LOOP AT it_filter_select_options INTO ls_filter_select_options.
IF ls_filter_select_options-property EQ 'PRODUCT_ID'.
LOOP AT ls_filter_select_options-select_options INTO
ls_select_option.
ls_selparamproductid-sign = ls_select_option-sign.
ls_selparamproductid-option = ls_select_option-option.
ls_selparamproductid-low = ls_select_option-low.
ls_selparamproductid-high = ls_select_option-high.
APPEND ls_selparamproductid TO lt_selparamproductid.
ENDLOOP.
ENDIF.
ENDLOOP.
SELECT product_id type_code category name description
supplier_id FROM zproductdetails INTO CORRESPONDING FIELDS OF TABLE
lt_headerdata WHERE product_id IN lt_selparamproductid .
LOOP AT lt_headerdata INTO ls_headerdata.
11
ls_product-product_id = ls_headerdata-product_id.
ls_product-type_code = ls_headerdata-type_code.
ls_product-category = ls_headerdata-category.
ls_product-name = ls_headerdata-name.
ls_product-description = ls_headerdata-description.
ls_product-supplier_id = ls_headerdata-supplier_id.
APPEND ls_product TO et_entityset.
ENDLOOP.
21) Entity(Read)
er_entity-supplier_id = ls_headerdata-supplier_id.
Use Code:
method PRODUCTSET_GET_ENTITY.
data:ls_key_tab TYPE /IWBEP/s_MGW_NAME_VALUE_PAIR,
LS_PRODUCT_ID TYPE ZPRODUCTDETAILS-PRODUCT_ID,
LS_HEADERDATA TYPE ZPRODUCTDETAILS.
loop at it_key_tab into ls_key_tab.
IF LS_KEY_TAB-NAME = 'PRODUCT_ID'.
LS_PRODUCT_ID = LS_KEY_TAB-VALUE.
ENDIF.
ENDLOOP.
SELECT SINGLE PRODUCT_ID TYPE_CODE CATEGORY NAME DESCRIPTION
SUPPLIER_ID FROM ZPRODUCTDETAILS INTO CORRESPONDING FIELDS OF
LS_HEADERDATA WHERE PRODUCT_ID = LS_PRODUCT_ID.
ER_ENTITY-PRODUCT_ID = LS_HEADERDATA-PRODUCT_ID.
ER_ENTITY-TYPE_CODE = LS_HEADERDATA-TYPE_CODE.
ER_ENTITY-CATEGORY = LS_HEADERDATA-CATEGORY.
ER_ENTITY-NAME = LS_HEADERDATA-NAME.
ER_ENTITY-DESCRIPTION = LS_HEADERDATA-DESCRIPTION.
er_entity-supplier_id = ls_headerdata-supplier_id.
12
endmethod.
BP_ID SNWD_PARTNER_ID
COMPANY_NAME SNWD_COMPANY_NAME
Go to Entity
13
Create properties Supplierid & Supplier Name
method SUPPLIERSET_GET_ENTITY.
DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,
ls_bp_id TYPE ZPARTNERDETAIL ,
ls_headerdata TYPE ZPARTNERDETAIL .
LOOP AT it_key_tab INTO ls_key_tab.
IF ls_key_tab-name EQ 'BP_ID'.
ls_bp_id-bp_id = ls_key_tab-value.
ENDIF.
ENDLOOP.
select single * from ZPARTNERDETAIL into CORRESPONDING FIELDS OF ls_headerda
ta where BP_ID = ls_bp_id-bp_id.
er_entity-BP_ID = ls_headerdata-bp_id.
er_entity-COMPANY_NAME = ls_headerdata-company_name.
endmethod.
/sap/opu/odata/sap/ZPRODUCTDETAIL_SRV/SupplierSet('0100000001')
25)
METHOD supplierset_get_entityset.
DATA: ls_bpheaderdata TYPE ZPARTNERDETAIL,
lt_bpheaderdata TYPE STANDARD TABLE OF ZPARTNERDETAIL,
ls_supplier LIKE LINE OF et_entityset.
select * from ZPARTNERDETAIL into CORRESPONDING FIELDS OF TABLE lt_bpheaderd
ata.
14
LOOP AT lt_bpheaderdata INTO ls_bpheaderdata.
ls_supplier-BP_ID = ls_bpheaderdata-bp_id.
ls_supplier-COMPANY_NAME = ls_bpheaderdata-company_name.
APPEND ls_supplier TO et_entityset.
ENDLOOP.
ENDMETHOD.
/sap/opu/odata/sap/ZPRODUCTDETAIL_SRV/SupplierSet?$format=json
26)
Now, for navigation between two entities we have to create association between to entities
A) Go to Association
15
B) You will get a pop up, provide details as
If we give cardinality 1 to 1 then get_entity method will trigger and if I give cardinality 0.n then
get_entityset method will trigger.
Click on next
C) Click next and Select the Dependent Property as SupplierID and click Next
D) Click on Finish
First metadata
16
/sap/opu/odata/sap/ZPRODUCTDETAIL_SRV/$metadata
METHOD supplierset_get_entity.
DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,
ls_bp_id TYPE zpartnerdetail,
ls_headerdata TYPE zpartnerdetail.
DATA: ls_product TYPE zcl_zproductdetail_mpc=>ts_product.
IF iv_entity_set_name EQ 'SupplierSet'.
CALL METHOD productset_get_entity
EXPORTING
iv_entity_name = iv_entity_name
iv_entity_set_name = iv_entity_set_name
iv_source_name = iv_source_name
it_key_tab = it_key_tab
io_request_object = io_request_object
io_tech_request_context = io_tech_request_context
it_navigation_path = it_navigation_path
IMPORTING
er_entity = ls_product.
ls_bp_id-bp_id = ls_product-supplier_id.
if ls_product is INITIAL.
LOOP AT it_key_tab INTO ls_key_tab.
IF ls_key_tab-name EQ 'BP_ID'.
ls_bp_id-bp_id = ls_key_tab-value.
ENDIF.
ENDLOOP.
endif.
ELSE.
LOOP AT it_key_tab INTO ls_key_tab.
IF ls_key_tab-name EQ 'SupplierID'.
ls_bp_id-bp_id = ls_key_tab-value.
ENDIF.
ENDLOOP.
ENDIF.
17
SELECT SINGLE * FROM zpartnerdetail INTO CORRESPONDING FIELDS OF ls_heade
rdata WHERE bp_id = ls_bp_id-bp_id.
er_entity-BP_ID = ls_headerdata-bp_id.
er_entity-COMPANY_NAME = ls_headerdata-company_name.
ENDMETHOD.
29)
Now,
Replace code of PRODUCTSET_GET_ENTITY
METHOD productset_get_entity.
DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,
ls_product_id TYPE zproductdetails-product_id,
ls_headerdata TYPE zproductdetails.
DATA: lr_mr_api TYPE REF TO if_mr_api.
lr_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).
LOOP AT it_key_tab INTO ls_key_tab.
IF ls_key_tab-name EQ 'PRODUCT_ID'.
ls_product_id = ls_key_tab-value.
ENDIF.
ENDLOOP.
SELECT SINGLE product_id type_code category name description
supplier_id FROM zproductdetails INTO CORRESPONDING FIELDS OF
ls_headerdata WHERE product_id = ls_product_id.
er_entity-product_id = ls_headerdata-product_id.
er_entity-type_code = ls_headerdata-type_code.
er_entity-category = ls_headerdata-category.
er_entity-name = ls_headerdata-name.
er_entity-description = ls_headerdata-description.
er_entity-supplier_id = ls_headerdata-supplier_id.
ENDMETHOD.
18
Now use URL
/sap/opu/odata/sap/ZPRODUCTDETAIL_SRV/ProductSet('HT-1000')/$links/ToSupplier
/sap/opu/odata/sap/ZPRODUCTDETAIL_SRV/ProductSet('HT-1000')/ToSupplier
19