Search code examples
odatasapui5abapsap-fiori

Create Deep Entity SAPUI5 - Item Data Not Transmitted


I used to the following tutorial to build a Fiori app with a deep entity (I used invoice header + items): https://blogs.sap.com/2017/07/18/steps-to-create-deep-insert-odata/

Everything works fine until I start debugging in the backend. The service sends the data correctly, in the backend, however, the items are missing. Backend code:

METHOD /iwbep/if_mgw_appl_srv_runtime~create_deep_entity.
    DATA custom_create_deep_entity TYPE zcl_xxx_mpc_ext=>ts_deep_entity.

    CASE iv_entity_set_name.
      WHEN 'xxxSet'.
        CALL METHOD me->custom_create_deep_entity
          EXPORTING
            iv_entity_name          = iv_entity_name
            iv_entity_set_name      = iv_entity_set_name
            iv_source_name          = iv_source_name
            it_key_tab              = it_key_tab
            it_navigation_path      = it_navigation_path
            io_expand               = io_expand
            io_tech_request_context = io_tech_request_context
            io_data_provider        = io_data_provider
          IMPORTING
            er_deep_entity          = custom_create_deep_entity.

        copy_data_to_ref(
          EXPORTING
            is_data = custom_create_deep_entity
          CHANGING
            cr_data = er_deep_entity
        ).
    ENDCASE.
  ENDMETHOD.

  METHOD custom_create_deep_entity.
    DATA: lr_deep_entity TYPE zcl_xxx_mpc_ext=>ts_deep_entity,
          lt_items       TYPE zcl_xxx_mpc=>tt_zinvoiceitem,
          ls_items       TYPE zcl_xxx_mpc=>ts_zinvoiceitem.

    io_data_provider->read_entry_data(
      IMPORTING
        es_data = lr_deep_entity ).

    ls_header_input = VALUE #(
      bukrs = lr_deep_entity-bukrs
      wrbtr = lr_deep_entity-wrbtr
    ).

    LOOP AT lr_deep_entity-items ASSIGNING FIELD-SYMBOL(<ls_item>).
      "never reached because 'items' is empty
    ENDLOOP.

    er_deep_entity = VALUE #(
      bukrs = ls_header_input-bukrs
      wrbtr = ls_header_input-wrbtr
      items = lr_deep_entity-items
    ).
  ENDMETHOD.

Redefined DEFINE method in class MPC_EXT:

  METHOD define.
    super->define( ).
    DATA:
      lo_annotation   TYPE REF TO /iwbep/if_mgw_odata_annotation,
      lo_entity_type  TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
      lo_complex_type TYPE REF TO /iwbep/if_mgw_odata_cmplx_type,
      lo_property     TYPE REF TO /iwbep/if_mgw_odata_property,
      lo_entity_set   TYPE REF TO /iwbep/if_mgw_odata_entity_set.

    lo_entity_type = model->get_entity_type( iv_entity_name = 'Zxxxxxx' ). 

    lo_entity_type->bind_structure( iv_structure_name  = 'ZCL_XXX_MPC_EXT=>TS_DEEP_ENTITY' ).
    ENDMETHOD.

Do I need to redefine any other methods that prohobit transferring the item data?

Thanks :)


Solution

  • How does the structure zcl_xxx_mpc_ext=>ts_deep_entity. looks like ?

    Change the names of the navigations and the underlying structure name for the navigation according to the types mentioned in Types tab in ‘__MPC_EXT’ class of your project. [Source]

    How does your payload look like while calling the Service ?

    If the payload look's right you clearly have a problem with your structure ts_deep_entity