cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with GET_EXPANDED_ENTITYSET

former_member188585
Participant
0 Kudos

Hello,

I have a requirement where I have to implement multi level expansion of entity-set for below both URI. 

  1. /sap/opu/odata/sap/ZZPHOENIX_004_SRV/SalesOrderSet/?$expand=OrderToItems
  2. /sap/opu/odata/sap/ZPHOENIX_004_SRV/SalesOrderSet/?$expand=OrderToItems/ItemToMaterial.

For OrderToItems/ItemToMaterial below code is working fine but when I am trying to call $expand = OrderToItems then it is going in LOOP. I am not sure why.

Below is my code in GET_EXPANDED_ENTITYSET method.


DATABEGIN OF t_orderitems.

             INCLUDE              TYPE  zcl_zphoenix_004_mpc_ext=>ts_salesorderitem.

     DATA: itemtomaterial TYPE  zcl_zphoenix_004_mpc_ext=>ts_material,

           END OF t_orderitems.

     DATABEGIN OF t_expand_so.

             INCLUDE             TYPE zcl_zphoenix_004_mpc_ext=>ts_salesorder.

     DATA: ordertoitems  LIKE TABLE OF t_orderitems,

          END OF t_expand_so.

     DATA: lt_expand_so   LIKE  TABLE OF t_expand_so,

           ls_expand_so   LIKE t_expand_so,

           ls_item        LIKE t_orderitems.

     DATA: lt_vbak  TYPE TABLE OF vbak,

           ls_vbak  LIKE LINE OF lt_vbak,

           lt_vbap  TYPE TABLE OF vbap,

           ls_vbap  TYPE  vbap,

           l_max_rows    TYPE i VALUE 20.

     DATA: lv_matnr TYPE matnr,

           ls_mara  TYPE mara.

     CONSTANTS: lc_expand_itemtomaterial  TYPE string VALUE 'ORDERTOITEMS/ITEMTOMATERIAL',

                lc_expand_ordertoitems    TYPE string VALUE 'ORDERTOITEMS'.

     SELECT * FROM vbak INTO TABLE lt_vbak UP TO l_max_rows ROWS ORDER BY erdat DESCENDING.

     IF sy-subrc EQ 0.

       SELECT * FROM vbap INTO TABLE lt_vbap FOR ALL ENTRIES IN lt_vbak WHERE vbeln = lt_vbak-vbeln.

     ENDIF.

* Data processing logic

     LOOP AT lt_vbak INTO ls_vbak.

       MOVE-CORRESPONDING ls_vbak TO ls_expand_so  .

       LOOP AT lt_vbap INTO ls_vbap WHERE vbeln = ls_vbak-vbeln.

         MOVE-CORRESPONDING ls_vbap TO ls_item  .

         lv_matnr = ls_vbap-matnr.

         CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

           EXPORTING

             input  = lv_matnr

           IMPORTING

             output = lv_matnr.

         SELECT SINGLE * FROM mara INTO ls_mara WHERE matnr = lv_matnr.

         MOVE-CORRESPONDING ls_mara TO ls_item-itemtomaterial.

         APPEND ls_item  TO ls_expand_so-ordertoitems.

         CLEAR: ls_item.

       ENDLOOP.

       APPEND ls_expand_so  TO lt_expand_so.

       CLEAR: ls_expand_so, lv_matnr.

     ENDLOOP.

* Fill EE_ENTITYSET

     copy_data_to_ref(

       EXPORTING

         is_data = lt_expand_so

       CHANGING

         cr_data = er_entityset ).

* Insert Navigation property into ET_EXPANDED_TECH_CLAUSES

     INSERT lc_expand_ordertoitems   INTO TABLE et_expanded_tech_clauses.

INSERT lc_expand_itemtomaterial INTO TABLE et_expanded_tech_clauses.

I have already checked below blogs but not able to understand this. Can someone suggest how to implement GET_EXPANDED_ENTITYSET method for a scenario A->B and A->B->C (where A and B is associated and B and C is associated)

Thanks,

~Rahul

Accepted Solutions (1)

Accepted Solutions (1)

AshwinDutt
Active Contributor
0 Kudos

Hello Rahul,


I am suspecting it is because, irrespective of firing the below URL's both the navigation properties are being append to the et_expanded_tech_clauses

  1. SalesOrderSet?$expand=OrderToItems
  2. SalesOrderSet?$expand=OrderToItems/ItemToMaterial.

When you fire

  1. SalesOrderSet?$expand=OrderToItems

INSERT only lc_expand_ordertoitems   INTO TABLE et_expanded_tech_clauses.

When you fire

  1. SalesOrderSet?$expand=OrderToItems/ItemToMaterial.

INSERT only lc_expand_itemtomaterial INTO TABLE et_expanded_tech_clauses. 


Please check this once.


Regards,

Ashwin

former_member188585
Participant
0 Kudos

Hello Ashwin,


You are right!!


I am suspecting it is because, irrespective of firing the below URL's both the navigation properties are being append to the et_expanded_tech_clauses

  1. SalesOrderSet?$expand=OrderToItems
  2. SalesOrderSet?$expand=OrderToItems/ItemToMaterial.

But my requirement is I have to build a logic in such a way that both navigation properties should work (without modifying code each time) and there is no parameter in GET_EXPANDED_ENTITYSET by which I can get which navigation property is requested for.

Is there any other way we can achieve this?

Thanks,

~Rahul

AshwinDutt
Active Contributor
0 Kudos

Hello Rahul,

I don not think you need to change the code here. All you need is to call the appropriate logic based on what is requested.

Did you see what values are getting filled in IT_NAVIGATION_PATH  when you fire the URL's ?

Please check this and this will contain the information. Based on that you can call logic and send back the correct response with Navigation Properties.

Regards,

Ashwin

former_member188585
Participant
0 Kudos

Hello Ashwin,

IT_NAVIGATION_PATH is coming empty.

Do we have any method by which we can read URI which is requested?

~Rahul

AshwinDutt
Active Contributor
0 Kudos

Hello Rahul,

Use IO_EXPAND to get the details as below.

For URL ->

SalesOrderSet?$expand=OrderToItems/ItemToMaterial.

IO_EXPAND  - > MT_CHILDREN -> You will get Navigation Property OrderToItems and a node reference to Material -> again inside this node  MT_CHILDREN will have Navigation Property ItemToMaterial

For URL ->

SalesOrderSet?$expand=OrderToItems

IO_EXPAND  - > MT_CHILDREN -> You will get Navigation Property OrderToItems


Please check this.


Regards,

Ashwin

former_member188585
Participant
0 Kudos

Awesome Ashwin.

Thanks,

Rahul

Answers (0)