SAP OData Code for Create Deep Entity

 #OData Create_Deep_Entity


Before adding the code in the method CREATE_DEEP_ENTITY first define the deep structure in MPC_EXT class.



Then add the code in CREATE_DEEP_ENTITY in DPC_EXT class


 method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY.

data begin of tp_expand.
        INCLUDE TYPE ZCL_ZK_DEMO2_MPC_EXT=>ts_soheader.
 data SOHEADERTOITEM type ZCL_ZK_DEMO2_MPC_EXT=>tt_soitem.
 data end of tp_expand.

* data : gt_expand like STANDARD TABLE OF tp_expand,
*        gs_expand like tp_expand,

 data gt_expand like STANDARD TABLE OF tp_expand,
        gs_expand type ZCL_ZK_DEMO2_MPC_EXT=>ts_deep_entity,

        gt_header type ZCL_ZK_DEMO2_MPC_EXT=>tt_soheader,
        gs_header type ZCL_ZK_DEMO2_MPC_EXT=>ts_soheader,

        gt_item type ZCL_ZK_DEMO2_MPC_EXT=>tt_soitem,
        gs_item type ZCL_ZK_DEMO2_MPC_EXT=>ts_soitem.

 data gv_vbeln type vbeln.


      CONSTANTSlc_expand_tech_clause TYPE string VALUE 'SOHEADERTOITEM'.

      read TABLE it_key_tab into data(gs_key_tabwith KEY name 'Vbeln'.
      gv_vbeln gs_key_tab-value.

      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input         gv_vbeln
       IMPORTING
         OUTPUT        gv_vbeln.

"read the entity data
  TRY.
  CALL METHOD io_data_provider->read_entry_data
    IMPORTING
      es_data gs_expand.

   CATCH /iwbep/cx_mgw_tech_exception .
  ENDTRY.


     MOVE-CORRESPONDING gs_expand to gs_header.

     modify zovbak from gs_header.
     if sy-subrc 0.
     gt_item[] gs_expand-soheadertoitem[].

     try.
     INSERT zovbap FROM TABLE gt_item.
     gs_expand-remark 'Record created successfully.'.
     CATCH cx_root.
     gs_expand-remark 'error while inserting record'.
     ENDTRY.

     else.
     endif.

      case IV_ENTITY_SET_NAME.

      when 'SOHEADERSet'.


      copy_data_to_ref(
        EXPORTING
          is_data gs_expand
        CHANGING
          cr_data er_deep_entity
      ).

      endcase.

  endmethod.



Post a Comment

0 Comments

Total Pageviews