*--------------------------------------------------------------------*
* Deep Structure
*--------------------------------------------------------------------*
TYPES: BEGIN OF ty_deep_entity,
vbeln TYPE vbeln_va, "Sales Document
erdat TYPE erdat, "Date on which the record was created
erzet TYPE erzet, "Entry time
ernam TYPE ernam, "Name of Person who Created the Object
vkorg TYPE vkorg, "Sales Organization
* Navigation property name should be used otherwise empty records will be shown
headertoitem TYPE TABLE OF ts_sales_item_data WITH DEFAULT KEY,
END OF ty_deep_entity.
*--------------------------------------------------------------------*
METHOD /iwbep/if_mgw_appl_srv_runtime~get_expanded_entityset.
DATA : lt_deep_entity TYPE TABLE OF zcl_zgw_practice006_mpc_ext=>ty_deep_entity, "Deep Entity Type
ls_deep_entity TYPE zcl_zgw_practice006_mpc_ext=>ty_deep_entity, "Deep Entity Type
ls_item TYPE zcl_zgw_practice006_mpc_ext=>ts_sales_item_data.
* Based on the entity set
IF iv_entity_set_name = 'Sales_Header_DataSet'.
SELECT * FROM vbak
INTO TABLE @DATA(lt_vbak)
* UP TO 20 ROWS.
WHERE vbeln = '0000018338'. "According to the requirements
IF sy-subrc = 0.
SELECT * FROM vbap
INTO TABLE @DATA(lt_vbap)
FOR ALL ENTRIES IN @lt_vbak
WHERE vbeln = @lt_vbak-vbeln.
ENDIF.
IF lt_vbak IS NOT INITIAL AND lt_vbak IS NOT INITIAL.
SORT lt_vbak DESCENDING BY vbeln.
SORT lt_vbap DESCENDING BY vbeln.
LOOP AT lt_vbak INTO DATA(ls_vbak_item).
ls_deep_entity = CORRESPONDING #( ls_vbak_item ).
IF line_exists( lt_vbap[ vbeln = ls_deep_entity-vbeln ] ).
LOOP AT lt_vbap INTO DATA(ls_vbap_item) FROM sy-tabix.
IF ls_vbak_item-vbeln <> ls_vbap_item-vbeln.
EXIT.
ENDIF.
ls_item = CORRESPONDING #( ls_vbap_item ).
* Appending to the deep structure
APPEND ls_item TO ls_deep_entity-headertoitem.
CLEAR ls_item.
ENDLOOP.
APPEND ls_deep_entity TO lt_deep_entity.
ENDIF.
CLEAR ls_vbak_item.
ENDLOOP.
ENDIF.
* For converting the data in the deep structure to the output format
CALL METHOD me->/iwbep/if_mgw_conv_srv_runtime~copy_data_to_ref
EXPORTING
is_data = lt_deep_entity
CHANGING
cr_data = er_entityset.
ENDIF.
ENDMETHOD.
/sap/opu/odata/sap/ZGW_PRACTICE006_SRV/Sales_Header_DataSet?$expand=HeaderToItem&$format=json
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 |