Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
JerryWang
Advisor
Advisor


This blog is the last part of the extension series. In the previous three blogs, we have already created extension field on the UI of CRM Fiori application "My Opportunities":








That means, the read and update operation on extension fields are already supported. In this blog, we will finish the left part: support creation operation as well. The UI after enhancement would look like below:


Step1 add new extension field in creation UI view


The logic is exactly the same as how we have added the extension in detail view and edit view. To avoid duplication the source code is not listed here:



See complete UI source code from github: https://github.com/i042416/testOpportunityExtension



Step2 Create sub class based on CL_CRM_OPPORTUNITY_IMPL


In my blog, the sub class is ZCL_CRM_OPPORTUNITY_IMPL_SUB. Only one method below needs redefinition.


The purpose of this redefined method are to populate necessary information regarding extension field passed from UI and store them in internal table et_customer_h and et_input_fields, which will be used in function module CRM_ORDER_MAINTAIN for opportunity creation.



METHOD create_oppt_header_input.
CALL METHOD super->create_oppt_header_input
EXPORTING
is_oppt_exp_hdr = is_oppt_exp_hdr
iv_handle = iv_handle
IMPORTING
ev_relationid = ev_relationid
et_opport_h = et_opport_h
et_input_fields = et_input_fields
ev_object_guid = ev_object_guid
et_orderadm_h = et_orderadm_h
et_pricing = et_pricing
et_partner = et_partner
et_orgman = et_orgman
et_customer_h = et_customer_h.
DATA: ls_input TYPE crmt_input_field,
ls_input_name TYPE crmt_input_field_names,
ls_customer_h LIKE LINE OF et_customer_h.
* The code below is responsible for populate it_customer_h internal table
* which is to be used in FM CRM_ORDER_MAINTAIN later
ls_customer_h-fld00008c = is_oppt_exp_hdr-ext_created_by.
ls_customer_h-ref_guid = ev_object_guid.
APPEND ls_customer_h TO et_customer_h.
* The code below is responsible for populate CT_INPUT_FIELDS internal table
* which is to be used in FM CRM_ORDER_MAINTAIN later
ls_input-objectname = 'CUSTOMER_H'.
ls_input-ref_guid = ev_object_guid.
ls_input-ref_kind = 'A'.
* Notify One order function module that we want to persist the value of this field
ls_input_name-fieldname = 'FLD00008C'.
APPEND ls_input_name TO ls_input-field_names.
INSERT ls_input INTO TABLE et_input_fields.
ENDMETHOD.

Step3 Redefine /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY


Redefine method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY of your own OData service implementation class. The idea is simple, just replace the usage of standard CL_CRM_OPPORTUNITY_IMPL to your own sub class created in step2.



method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY.
DATA: lr_opportunity TYPE crmt_odata_oppt_hdr_expanded,
lo_oppt_impl TYPE REF TO zcl_crm_opportunity_impl_sub.
CREATE OBJECT lo_oppt_impl.
lo_oppt_impl->/iwbep/if_mgw_core_srv_runtime~set_context( mo_context ).
lo_oppt_impl->create_deep_oppt_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_expand = io_expand
io_tech_request_context = io_tech_request_context
IMPORTING
er_deep_entity = lr_opportunity ). " Table of Strings
copy_data_to_ref( EXPORTING is_data = lr_opportunity
CHANGING cr_data = er_deep_entity ).
endmethod.

Till now all steps are done. Please see the final achievement regarding extension field CRUD operation from this video:


https://github.com/i042416/jerryslide/blob/master/video/extensionFieldCRUD.wmv