cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to get Multi level entities in the Response body using GET_EXPANDED_ENTITYSET?

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Answers (1)

Answers (1)

JyotiD
Active Participant
0 Kudos

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

Former Member
0 Kudos

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

JyotiD
Active Participant
0 Kudos

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

Former Member
0 Kudos

Hi Tarun,

I have checked in Debugger and my final table has values.

ER_ENTITYSET also has the values:

    copy_data_to_ref(

             EXPORTING

                is_data = lt_detl

             CHANGING

                cr_data = er_entityset ).


Somehow, the values are not appearing in the response body.

Thanks,

Faraz Khan

JyotiD
Active Participant
0 Kudos

Hi farz,

Did you try calling same in browser or in json format.

Regards,

Tarun

Former Member
0 Kudos

Hi Tarun,

Thanks a lot for your help on this.

After making few adjustments in the Response Body structure, I was able to get the desired output but only in JSON format.

I will share the final resolution details shortly.

Regards,

Faraz Khan

JyotiD
Active Participant
0 Kudos

Great Faraz,

Reason for not getting output in XML maybe due to "Response  body is too large ". Is there any such message coming in response screen.  Did you try calling in Response in browser in case of XML.

Json is more compact and less data is transferred.

Regards,

Tarun