on 03-06-2016 8:11 AM
Hello,
I have a requirement where I have to implement multi level expansion of entity-set for below both URI.
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.
DATA: BEGIN 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.
DATA: BEGIN 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
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
When you fire
INSERT only lc_expand_ordertoitems INTO TABLE et_expanded_tech_clauses.
When you fire
INSERT only lc_expand_itemtomaterial INTO TABLE et_expanded_tech_clauses.
Please check this once.
Regards,
Ashwin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
- SalesOrderSet?$expand=OrderToItems
- 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
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
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
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.