Support read and update operation on CUSTOMER_H extension fields

118 阅读1分钟

Created by Jerry Wang, last modified on Dec 24, 2015

import note 2183832, and then:

  1. /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITY - no change
  2. /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY - no change
  3. /IWBEP/IF_MGW_APPL_SRV_RUNTIME~PATCH_ENTITY:

keypoint

a. you have to manually insert entry to cl_crm_opportunity_impl=>gt_customer_h in your own code:
[外链图片转存失败(img-GDVe3wH4-1562295211610)(user-images.githubusercontent.com/5669954/275…)]

b. you have to manually insert entry to cl_crm_opportunity_impl=>gt_input_fields in your own code as well:

[外链图片转存失败(img-AyV3voPg-1562295211612)(user-images.githubusercontent.com/5669954/275…)]

complete source code

  METHOD /iwbep/if_mgw_appl_srv_runtime~patch_entity.
    CALL METHOD super->/iwbep/if_mgw_appl_srv_runtime~patch_entity
      EXPORTING
        iv_entity_name          = iv_entity_name
        iv_entity_set_name      = iv_entity_set_name
        iv_source_name          = iv_source_name
        io_data_provider        = io_data_provider
        it_key_tab              = it_key_tab
        it_navigation_path      = it_navigation_path
        io_tech_request_context = io_tech_request_context
      IMPORTING
        er_entity               = er_entity.
    FIELD-SYMBOLS: <header_from_ui> TYPE crmt_odata_oppt_header,
                   <header_buffer>  TYPE crmt_customer_h_com,
                   <value_ui>       TYPE crmt_odata_oppt_header-ext_created_by,
                   <input_fields>   LIKE LINE OF cl_crm_opportunity_impl=>gt_input_fields.
* Jerry: in CL_CRM_OPPORTUNITY_impl=>PATCH_OPPT_HEADER_ENTITY only extension field name
* like "fld00008c" is passed in, and it is impossible for us to determine which BO part this
* extension field comes from, eg from OPPORT_H or CUSTOMER_H?
* as a result, it is necessary for extension developer to specify mapping in this method
    DATA: ls_input TYPE crmt_input_field_names.
    CHECK iv_entity_name = 'Opportunity'.
    ASSIGN er_entity->* TO <header_from_ui>.
    CHECK sy-subrc = 0.
    ASSIGN COMPONENT 'EXT_CREATED_BY' OF STRUCTURE <header_from_ui> TO <value_ui>.
    CHECK sy-subrc = 0.
    DATA: ls_customer_h LIKE LINE OF cl_crm_opportunity_impl=>gt_customer_h.
    ls_customer_h-fld00008c = <value_ui>.
    ls_customer_h-ref_guid = <header_from_ui>-guid.
    APPEND ls_customer_h TO cl_crm_opportunity_impl=>gt_customer_h.
    DATA: ls_customer_h_input LIKE LINE OF cl_crm_opportunity_impl=>gt_input_fields,
          ls_name LIKE LINE OF ls_customer_h_input-field_names.
    ls_customer_h_input-ref_guid = <header_from_ui>-guid.
    ls_customer_h_input-ref_kind = 'A'.
    ls_customer_h_input-objectname = 'CUSTOMER_H'.
    ls_name-fieldname = 'FLD00008C'.
    APPEND ls_name TO ls_customer_h_input-field_names.
    INSERT ls_customer_h_input INTO TABLE cl_crm_opportunity_impl=>gt_input_fields.
  ENDMETHOD.