*--------------------------------------------------------------------*
* 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.
*--------------------------------------------------------------------*
DATA lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ.
super->define( ).
* Header Entity Name
lo_entity_type = model->get_entity_type( iv_entity_name = 'Sales_Header_Data' ).
* MPC_EXT Deep Structure Name
lo_entity_type->bind_structure( iv_structure_name = 'ZCL_ZGW_PRACTICE006_MPC_EXT=>TY_DEEP_ENTITY
METHOD /iwbep/if_mgw_appl_srv_runtime~create_deep_entity.
DATA : ls_deep_entity TYPE zcl_zgw_practice006_mpc_ext=>ty_deep_entity,
lt_item TYPE TABLE OF zcl_zgw_practice006_mpc_ext=>ts_sales_item_data,
ls_header TYPE zcl_zgw_practice006_mpc_ext=>ts_sales_header_data.
* Methods/FMs should be used in case of direct database table update
* Reading the entity data through the parameter: io_data_provider
TRY.
CALL METHOD io_data_provider->read_entry_data
IMPORTING
es_data = ls_deep_entity.
IF ls_deep_entity IS NOT INITIAL.
ls_header = CORRESPONDING #( ls_deep_entity ).
ls_header-mandt = sy-mandt.
MODIFY vbak FROM ls_header.
IF sy-subrc = 0.
lt_item[] = CORRESPONDING #( ls_deep_entity-headertoitem[] ).
DO lines( lt_item[] ) TIMES.
lt_item[ sy-index ]-mandt = sy-mandt.
ENDDO.
TRY.
INSERT vbap FROM TABLE lt_item ACCEPTING DUPLICATE KEYS.
IF sy-subrc = 4. "To overcome the dump
CALL METHOD me->copy_data_to_ref "Populating the ER_DEEP_ENTITY
EXPORTING
is_data = ls_deep_entity
CHANGING
cr_data = er_deep_entity.
ENDIF.
CATCH cx_root.
"Error during insert
ENDTRY.
ENDIF.
ENDIF.
CATCH /iwbep/cx_mgw_tech_exception.
"Do Nothing[
ENDTRY.
ENDMETHOD.
{
"Vbeln" : "0000032183",
"Erdat" : "\/Date(1481760000000)\/",
"Erzet" : "TEST0000001",
"Ernam" : "Kallol",
"Vkorg" : "1710",
"HeaderToItem" : [
{
"Vbeln" : "0000032183",
"Posnr" : "000010",
"Matnr" : "MZ-FG-M550",
"Arktx" : "M550 BIKE",
"Posar" : ""
},
{
"Vbeln" : "0000032183",
"Posnr" : "000020",
"Matnr" : "LMO-PRD-M121",
"Arktx" : "1ortable DVD Player PDP-121",
"Posar" : ""
},
{
"Vbeln" : "0000032183",
"Posnr" : "000030",
"Matnr" : "MZ-FG-C950",
"Arktx" : "C950 BIKE",
"Posar" : ""
}
]
}
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 | |
9 | |
9 | |
7 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 |