Skip to Content

NWGW - Multi Level $expand not expanded 2nd entity

Hi all,

I am trying to implement a multi level expand (EntityA$expand=EntityB/EntityC) but it is not working for the entity C - it is returning blank).

I can see in debug that the entityset, from the expand method, is being overwritten by a 5 column entity set from standard SAP (only showing entity A and ToItems (Entity B)).

My expand logic is filling the data correctly.

Results:

URL:

../TrolleyHeaderSet?$expand=ToItems/ToMaterials

SEGW:

Association:

Debug:

Expand code:

CASE iv_entity_set_name.
    WHEN 'TrolleyHeaderSet'.
      DATA: "lt_expand  TYPE STANDARD TABLE OF zswm_gw_trolley_expand,
            lt_filters TYPE /iwbep/t_mgw_select_option,
            ls_filter  TYPE /iwbep/s_mgw_select_option,
            lv_filter  TYPE zewm_zone.

      lv_expand_tech_clause = io_tech_request_context->get_expand( ).
      TRANSLATE lv_expand_tech_clause TO UPPER CASE.

  DATA: BEGIN OF ty_expand.
      INCLUDE TYPE zcl_zgw_picking_soluti_mpc_ext=>ts_trolleyheader.
    DATA: toitems TYPE zcl_zgw_picking_soluti_mpc_ext=>tt_trolleyitems,
      tomaterials TYPE zcl_zgw_picking_soluti_mpc_ext=>tt_trolleymaterials,
  END OF ty_expand.

DATA: lt_trolleys  TYPE STANDARD TABLE OF zswm_trolley_ctrl,
 lt_trolley_header TYPE zcl_zgw_picking_soluti_mpc_ext=>tt_trolleyheader,
 lt_trolley_item   TYPE zcl_zgw_picking_soluti_mpc_ext=>tt_trolleyitems,
 lt_trolley_mats   TYPE zcl_zgw_picking_soluti_mpc_ext=>tt_trolleymaterials,
 lt_expand         LIKE STANDARD TABLE OF ty_expand.

DATA: ls_trolley_header TYPE zcl_zgw_picking_soluti_mpc_ext=>ts_trolleyheader,
 ls_trolley_item   TYPE zcl_zgw_picking_soluti_mpc_ext=>ts_trolleyitems,
 ls_materials      TYPE zcl_zgw_picking_soluti_mpc_ext=>ts_trolleymaterials,
 ls_expand         LIKE LINE OF lt_expand.

 SELECT * FROM ztwm_trolleyctrl INTO CORRESPONDING FIELDS OF TABLE lt_trolleys.
      IF sy-subrc <> 0.
        RETURN.
      ENDIF.

      LOOP AT lt_trolleys ASSIGNING FIELD-SYMBOL(<fs_trolleys>).
        MOVE-CORRESPONDING <fs_trolleys> TO ls_trolley_header.
        APPEND ls_trolley_header TO lt_trolley_header.
        MOVE-CORRESPONDING <fs_trolleys> TO ls_trolley_item.
        APPEND ls_trolley_item TO lt_trolley_item.
      ENDLOOP.

      lt_trolley_mats = zcl_wm_picking_solution=>get_materials( ).

      SORT lt_trolley_header BY trolley_type ASCENDING.
      SORT lt_trolley_item   BY trolley_id ASCENDING trolley_type ASCENDING.
      SORT lt_trolley_mats   BY trolley_id ASCENDING trolley_type ASCENDING material ASCENDING.

      DELETE ADJACENT DUPLICATES FROM lt_trolley_header.

      LOOP AT lt_trolley_header ASSIGNING FIELD-SYMBOL(<fs_header>).
        MOVE-CORRESPONDING <fs_header> TO ls_expand.
        LOOP AT lt_trolley_item ASSIGNING FIELD-SYMBOL(<fs_item>) WHERE trolley_type = <fs_header>-trolley_type.
          APPEND <fs_item> TO ls_expand-toitems.
        ENDLOOP.
        LOOP AT lt_trolley_mats ASSIGNING FIELD-SYMBOL(<fs_material>) WHERE trolley_type = <fs_header>-trolley_type.
          APPEND <fs_material> TO ls_expand-tomaterials.
        ENDLOOP.
        APPEND ls_expand TO lt_expand.
        CLEAR ls_expand.
      ENDLOOP.

    WHEN OTHERS.
      RETURN.
  ENDCASE.

  copy_data_to_ref(
    EXPORTING
      is_data = lt_expand
    CHANGING
      cr_data = er_entityset ).

  APPEND lv_expand_tech_clause TO et_expanded_tech_clauses.
segw.jpg (48.1 kB)
cardinality.jpg (23.9 kB)
debug.jpg (168.9 kB)
debug.jpg (168.9 kB)
response.jpg (72.3 kB)
Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Jul 10, 2018 at 01:01 PM

    Hi James!

    Nice to talk to you again.

    Not sure what version of Gateway you have but have you tried looking at some relevant SAP notes - this one in particular 2087759 - Empty result on $expand although data exists

    If not valid, does it work when you select for EntityB expanding on EntityC?

    Oli

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 11, 2018 at 05:24 PM

    Hi,

    It may be because your implementation of $expand is getting over written by standard framework's implementation because framework is not recognizing that you have handled the third level expand with custom code.

    In such cases, please check what is getting appended to et_expanded_tech_clauses.

    You should append as below

    Append 'ENTITYB' to et_expanded_tech_clauses.

    Append 'ENTITYB/ENTITYC' to et_expanded_tech_clauses.


    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.