Objective: Retrieving Association Data from an OData service
Create Association Between EntitySet
- Create New Entity Type with Detail Item Data
- Create New Association
on folder icon named Association, right click > create
then following the wizard,

Principal Entity -> Header
Where table contain Header Records (ZET_USER_PROFILE)
Dependent Entity -> Detail Item
Where table contain Detail Item (ZET_USER_SKILL)
Cardinality means relation between table, here we set the relation between header->item are one to many.
So we set cardinality header with 1 then cardinality for item 1..n
The key we set into pernr.
- Generate Runtime Object
- Redefine Method ZETXXX_GET_ENTITYSET with below source code
METHOD zet_user_skillse_get_entityset.
“Declaration of Local Navigation
DATA: lt_nav_path TYPE /iwbep/t_mgw_tech_navi,
ls_nav_path TYPE /iwbep/s_mgw_tech_navi.
“Declaration of Input Parameter Structure
DATA: lx_key_tab LIKE LINE OF it_key_tab,
lx_entityset LIKE LINE OF et_entityset.
“Declaration of Internal Table
DATA: lx_user_skill TYPE zta_fio_skill,
lt_user_skill TYPE TABLE OF zta_fio_skill.
“Local Variable
DATA: lv_pernr TYPE char5,
lv_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 = ‘TOSKILLS’.
IF sy–subrc = 0.
“1) Request URI using Association
“/sap/opu/odata/sap/ZUSER_PROFILE_SRV/ZET_USER_PROFILESet(‘xxxxx’)/ToSkills
READ TABLE it_key_tab INTO lx_key_tab WITH KEY name = ‘Pernr’.
IF sy–subrc = 0.
lv_pernr = lx_key_tab–value.
ENDIF.
REFRESH: lt_user_skill[].
SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_user_skill
FROM zta_fio_skill
WHERE pernr = lv_pernr.
IF lt_user_skill[] IS NOT INITIAL.
LOOP AT lt_user_skill INTO lx_user_skill.
MOVE-CORRESPONDING lx_user_skill
TO lx_entityset.
APPEND lx_entityset TO et_entityset.
ENDLOOP.
ENDIF.
ELSE.
“2) Request URI using Filter
“/sap/opu/odata/sap/ZUSER_PROFILE_SRV/ZET_USER_SKILLSet?$filter=Pernr eq ‘xxxxx’
lv_where_clause = io_tech_request_context->get_osql_where_clause_convert( ).
SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_user_skill
FROM zta_fio_skill
WHERE (lv_where_clause).
IF lt_user_skill[] IS NOT INITIAL.
LOOP AT lt_user_skill INTO lx_user_skill.
MOVE-CORRESPONDING lx_user_skill
TO lx_entityset.
APPEND lx_entityset TO et_entityset.
ENDLOOP.
ENDIF.
ENDIF.
ENDMETHOD.
- Testing go to /n/IWFND/MAINT_SERVICE > your_service_srv > SAP Gateway Service
>Request URI using Association
IMPORTANT: make sure the navigation property is set correctly.
Navigation Property is used for Relation between Entity Types that used as Request URI using Association. To check that open SEGW, check under Entity Types > Header Entity Types (ZET_USER_PROFILE) > Navigation Properties

/sap/opu/odata/sap/ZUSER_PROFILE_SRV/ZET_USER_PROFILESet(‘00001’)/ToSkills

Result:

>Request URI using Filter
/sap/opu/odata/sap/ZUSER_PROFILE_SRV/ZET_USER_SKILLSet?$filter=Pernr eq ‘00001’

Result:
