on 05-06-2016 5:29 PM
Hi Everyone,
I have a requirement where I have to get the Response payload in the following way:
<E1>
<RefreshOnDate>2016-04-08</RefreshOnDate>
<E2>
<LabelName>VACATION</LabelName>
<E3>
<Code>B001</Code>
<Group>ABSENCE</Group>
<Description>VACATION</Description>
<OrderOfDisplay>1</OrderOfDisplay>
<IsLeaveIdNeeded>N</IsLeaveIdNeeded>
</TimeCode></TimeLabel><TimeLabel>
</E3>
</E2>
</E1>
As we can see in the above response body, we have 3 levels of hierarchy.
E1 has E2(Table Type) as one of its fields, and E2 has E3(Table Type) as one of its fields.
I have created three separate entities in Gateway builder and have joined then through associations and Navigation.
How in my DPC_EXT method should I pass the Response structure as mentioned above?
Currently, I have used the below structure but the problem is, each entity appears separately in the Response; whereas I want the above mentioned format with nested entities like E1->E2->E3.
DATA : BEGIN OF lw_detl.
INCLUDE TYPE zcl_timecod_mpc=>ts_e1.
DATA : e2 TYPE STANDARD TABLE OF zcl_timecod_mpc=>ts_e2 WITH DEFAULT KEY,
e3 TYPE STANDARD TABLE OF zcl_timecod_mpc=>ts_e3 WITH DEFAULT KEY,
END OF lw_detl.
URI used : /sap/opu/odata/sap/ZTMSRV/E1SET?$filter=RefreshOnDate eq '2016-04-08'&$expand=E2,E3
Please suggest.
Thanks,
Faraz Khan
Hi Everyone,
Below is the solution:
Create entities, association, and navigation as shown in the original post, at the top.
In Method DPC_EXT, declare the structure as shown below:
Be very careful about the names of the entities.
TYPES: BEGIN OF ty_deep.
INCLUDE TYPE zcl_ztm_mytime_timecod_mpc=>ts_e2.
TYPES:e3 TYPE STANDARD TABLE OF zcl_ztm_mytime_timecod_mpc=>ts_e3
WITH DEFAULT KEY,
END OF ty_deep.
DATA : BEGIN OF lw_detl.
INCLUDE TYPE zcl_ztm_mytime_timecod_mpc=>ts_e1.
DATA : e2 TYPE STANDARD TABLE OF ty_deep WITH DEFAULT KEY,
END OF lw_detl.
********Your logic here*********
Since, ours is a nested structure like E1-->E2-->E3.
Use '/' while moving navigation to et_expanded_tech_clauses.
MOVE 'E2/E3' TO lv_expa.
APPEND lv_expa TO et_expanded_tech_clauses.
URI : /sap/opu/odata/sap/ZTMSRV/E1SET?$filter=RefreshOnDate eq '2016-04-08'&$expand=E2/E3&$format=json
Thanks,
Faraz Khan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Faraz,
Why you are using this URL ?
URI used : /sap/opu/odata/sap/ZTMSRV/E1SET?$filter=RefreshOnDate eq '2016-04-08'&$expand=E2,E3
This URL means you are Navigating between E1 -> E2 and E1 -> E3, however you have mentioned that you have multi level hierarchy i.e E1 -> E2 and then E2 -> E3.
you should use url /sap/opu/odata/sap/ZTMSRV/E1SET?$filter=RefreshOnDate eq '2016-04-08'&$expand=E2/E3
Similarly there will be change in your data declaration also as currently there are 2 tables e2 and e3 declared in lw_detl.
This may be the reason for you to have response structure as E2 and E3 inside E1.
Regards,
Tarun
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tarun,
Thanks for your suggestion
I have made the changes suggested by you in the URI and the Response Structure,but I am getting blank response body with only fields names.
Below is the new structure:
DATA : BEGIN OF lw_detl.
INCLUDE TYPE zcl_timecod_mpc=>ts_e1.
DATA : e2 TYPE STANDARD TABLE OF t_T_T WITH DEFAULT KEY,
END OF lw_detl.
Here T_T_T is :
TYPES: BEGIN OF t_t_t,
label TYPE zcl_timecod_mpc=>ts_e2,
time_code TYPE STANDARD TABLE OF zcl_timecod_mpc=>ts_e3
WITH DEFAULT KEY,
END OF t_t_t.
New URI: /sap/opu/odata/sap/ZTMSRV/E1SET?$filter=RefreshOnDate eq '2016-04-08'&$expand=E2/E3
Also, In DPC_EXT I have passed the navigation properties as shown below:
copy_data_to_ref(
EXPORTING
is_data = lt_detl
CHANGING
cr_data = er_entityset ).
MOVE 'E2' TO lv_expa.
APPEND lv_expa TO et_expanded_tech_clauses.
Please review and provide your feedback.
Thanks,
Faraz Khan
Hi Faraz,
Please try it like this. I think your final table lt_detl is having values.
DATA: BEGIN OF wa_E2.
INCLUDE TYPE zcl_timecod_mpc=>ts_e2.
DATA: E3 TYPE zcl_timecod_mpc=>tt_e3,
END OF wa_E2.
DATA: BEGIN OF wa_E1.
INCLUDE TYPE zcl_timecod_mpc=>ts_inspoperation.
DATA: E2 LIKE TABLE OF wa_E2,
END OF wa_E1.
DATA: LT_DETL LIKE STANDARD TABLE OF WA_E1.
******************* Your Logic**************************
copy_data_to_ref(
EXPORTING
is_data = LT_DETL
CHANGING
cr_data = er_entity
).
Keep Breakpoints and check if your final table lt_detl is having values ?
Regards,
Tarun
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.