Skip to Content
Author's profile photo Jerry Wang

An example of End to End extension on CRM Fiori application – part1

These series of blogs give a step-by-step instructions about how to extend SAP standard CRM Fiori application in an End-to-End way.

The CRM application “My Opportunity” is used as example. End-to-End means:

  • Enhance the standard OData model to fulfill customer specific business requirement which could not be covered by standard.

Technically, it means new extension fields are enhanced upon related standard DDIC structures. The Create, Read, Update and Delete operations are supported upon those extension fields.

  • Enhance the runtime OData service implementation to manipulate on the OData extensions done by step1.
  • Consume the extension fields exposed enhanced OData service done by step1 & step2 in UI.

This article will cover step1 & step2. The involved scenario is:

1. enhance a new field in OData model to store the user name who creates the current Opportunity currently being read.

2. enhance the OData service’s read operation, so that this extension field is filled with correct value in the backend.

Step1 Create extension project using transaction code SEGW

This extension project is used to store all kinds of extensions on standard gateway project CRM_OPPORTUNITY

/wp-content/uploads/2015/06/clipboard1_727789.png

choose Redefine->OData Service(SAP GW):

/wp-content/uploads/2015/06/clipboard2_727790.png

Select standard project: CRM_OPPORTUNITY

/wp-content/uploads/2015/06/clipboard3_727791.png

Just select all entities and click Finish button.

/wp-content/uploads/2015/06/clipboard4_727792.png

Generate all Runtime artifacts, ensure successful generation:

/wp-content/uploads/2015/06/clipboard5_727794.png

Use default proposed name or change according to your own naming convention. Write down your technical service Name, here is ZJERRY_DEMO_SRV:

/wp-content/uploads/2015/06/clipboard6_727795.png

Step2 Register your extension service in gateway ( frontend ) system

Till now we haven’t done any extension yet, which means all the CRUD operations on Opportunity should work.

Log on to your gateway system, use transaction code /IWFND/MAINT_SERVICE, click Add Service button:

/wp-content/uploads/2015/06/clipboard8_727848.png

/wp-content/uploads/2015/06/clipboard7_727847.png

Search by the technical service name which you got in step 1:

/wp-content/uploads/2015/06/clipboard9_727849.png

Add the found technical service, then registration is done. Now you could test your service via gateway client.

/wp-content/uploads/2015/06/clipboard10_727850.png

Launch gateway client via this button:

/wp-content/uploads/2015/06/clipboard11_727851.png

Test whether metadata retrieve works.

/wp-content/uploads/2015/06/clipboard12_727852.png

Test whether read operation on given Opportunity instance specified by guid also works or not. Just replace the standard service name CRM_OPPORTUNITY with your own one: ZJERRY_DEMO_SRV:

/wp-content/uploads/2015/06/clipboard13_727862.png

/wp-content/uploads/2015/06/clipboard14_727863.png

Step3 Enhance OData model

Suppose we need to extend Opportunity header structure with new field which stores the information who has created the opportunity.

The first step is to figure out which DDIC structure you need to extend. In this example, since I need to extend Opportunity header, so I just look into data type TS_OPPORTUNITY defined in Opportunity MPC ( metadata provider class ),

/wp-content/uploads/2015/06/clipboard15_727866.png

types: TS_OPPORTUNITY type CRMT_ODATA_OPPT_HEADER.

If you need to do extension on any part of Opportunity, for example on product level, then use the structure defined in TS_OPPORTUNITYPRODUCT instead.

Create a new extension field EXT_CREATED_BY via append structure.

/wp-content/uploads/2015/06/clipboard16_727867.png

go to tcode SEGW, extend the OData model as well. Double click on the folder icon “Properties” of Opportunity node, create a new field:

/wp-content/uploads/2015/06/clipboard17_727871.png

Specify the field name, field type and the most important is the ABAP field name EXT_CREATED_BY must be bound to this field in model.

/wp-content/uploads/2015/06/clipboard18_727872.png

Once done, regenerate the runtime artifacts by clicking the icon “Generate Runtime Objects” in toolbar.

Till now your model enhancement is done.

<Note> every time you have make modifications on your OData model in backend system, to make it take effect, you have to clear the cache in both gateway and backend system separately, or else when your model is accessed in the runtime, still the old structure stored in cache table is used. You could not see the new field you just created.

Tcode to clear cache in frontend system: /IWFND/CACHE_CLEANUP

Tcode to clear cache in backend system: /IWBEP/CACHE_CLEANUP

Step4 finish data provider class enhancement

In this step, we must enhance the original OData service implementation: fetch the created by information of a given Opportunity being read and fill it to extension field EXT_CREATED_BY.

open your DPC_EXT class, and redefine method GET_ENTITY, as which will be called when an opportunity is read via its guid.

<Note> Please always make changes on the DPC_EXT class. All your changes on DPC class will get lost every time you click “Generate Runtime Objects” button in tcode SEGW.

/wp-content/uploads/2015/06/clipboard19_727873.png

paste the source code below to method implementation:

METHOD /iwbep/if_mgw_appl_srv_runtime~get_entity.
    CALL METHOD super->/iwbep/if_mgw_appl_srv_runtime~get_entity
      EXPORTING
        iv_entity_name          = iv_entity_name
        iv_entity_set_name      = iv_entity_set_name
        iv_source_name          = iv_source_name
        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
        es_response_context     = es_response_context.
*  Customer extension could be put here
    CASE iv_entity_name.
      WHEN 'Opportunity'.
*         Extension logic on Opportunity header
        CALL METHOD fill_created_by
          EXPORTING
            it_key_tab = it_key_tab
          CHANGING
            cr_entity  = er_entity.
      WHEN OTHERS.
    ENDCASE.
  ENDMETHOD.

And source code for private method fill_created_by:

method FILL_CREATED_BY.

     FIELD-SYMBOLS: <s_guid> LIKE LINE OF it_key_tab,

                    <opp_header> TYPE cl_crm_opportunity_mpc=>ts_opportunity,

                    <created_by> TYPE sy-uname.

     DATA: lv_created_by TYPE crmd_orderadm_h-created_by.

     ASSIGN cr_entity->* TO <opp_header>.

     ASSIGN COMPONENT 'EXT_CREATED_BY' of STRUCTURE <opp_header> TO <created_by>.

     CHECK sy-subrc = 0.

     READ TABLE it_key_tab ASSIGNING <s_guid> WITH KEY name = 'Guid'.

     CHECK sy-subrc = 0.

     SELECT SINGLE created_by INTO lv_created_by FROM crmd_orderadm_h WHERE guid = <s_guid>-value.

     IF sy-subrc = 0.

        <created_by> = lv_created_by.

     ENDIF.

  endmethod.

The signature of method:

methods FILL_CREATED_BY
    importing
      !IT_KEY_TAB type /IWBEP/T_MGW_NAME_VALUE_PAIR
    changing
      !CR_ENTITY type ref to DATA .

Then test in gateway client: the extension field is filled with correct data in the runtime.

/wp-content/uploads/2015/06/clipboard20_727874.png

In the next blog, it will introduce how to consume this extension field in Fiori UI.

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Hemendra Sabharwal
      Hemendra Sabharwal

      Thanks Jerry Wang, This is an awesome blog. It is really very helpful.

      Warm Regards

      Hemendra

      Author's profile photo Former Member
      Former Member

      Nice blog