Enhancing the CRM Middleware Example2

Example: Adding Customer ABC Classification

Introduction

Business Partners in ERP have a field called "Customer classification (ABC analysis)" on their Sales Data. This field does not exist in CRM hence is not replicated between the two systems.
The task was to create the field in CRM and have it replicated with ERP - in both ways. To achieve this, the CRM Middleware had to be enhanced.

From ERP to CRM

In the following chapter you'll find the developments done in the ERP and CRM system in order to send the ABC classification of a customer from ERP to CRM.

General information

ABC class. in ERP:

 Table

KNVV 

 Field

KLABC

 Key fields of table 

KUNNR, VKORG, VTWEG, SPART 


Enhancement Steps in ERP

Customizing of User Exit

The CRM Middleware can be enhanced using User Exits which are triggered by certain Interface Processes. These processes are found in table TPS01 whereas the ones starting with 'CRM' concern the middleware.
First however a so called Customer Product is needed which later on will be assigned to the user exit. The customer product is customized via sm30 of table TBE24. It consists of a product name, description, optionally of a RFC destination (if the called user exit is not in the same system) and an activation flag.

Product 

ZBPPRIE

 Text

BUPA Pricing Extension

 RFC-destination

 

 Active

X

Now a User Exit can be customized via sm30 of table TPS34. The process "user-exit before data is sent" is the one to use (CRM0_200). A new function module needs to be created and the newly added customer product needs to be assigned (through its activation flag is the user-exit called or not).

Process 

CRM0_200

 Country

 

 Appl.

 

 Function

Z_CRM_MW_BP_PRICING_OUT

 Product

ZBPPRIE 

Function for User Exit

Table TPS01 contains sample function modules for all processes with the corresponding parameter interface. It is best to copy the sample function of the process chosen; in this case SAMPLE_PROCESS_CRM0_200.
The TABLES-parameter T_BAPISTRUCT contains all data (tables, structures and fields) which will be sent to CRM. The standard structures cannot have append structures therefore enhancements must be appended to that table as if they were a table themselves (at least is this the only way I could find).

Function Z_CRM_MW_BP_PRICING_OUT

* Data defintions -----------------------------------------------------*
  TYPES: ty_knvv_t LIKE knvv OCCURS  0 .
 
  DATA: lt_complex            TYPE busei_com_extern_t,
        ls_complex            TYPE busei_com_extern,
        lt_not_processed      TYPE busei_bapimtcs_t,
 
        ls_partner            TYPE busei_com_instance,
        lv_customer           LIKE kna1-kunnr,
 
        ls_salesarea          TYPE busei_ccom_salesarea,
        lv_vkorg              TYPE vkorg,
        lv_knvv_tab           TYPE string,
 
        BEGIN OF ls_mtcs_lite,
          currdno             TYPE currdno,
          objkey              TYPE crmobjkey,
          relkey              TYPE crmrelkey,
        END   OF ls_mtcs_lite.
 
  FIELD-SYMBOLS: <fs_knvv_t> TYPE ty_knvv_t,
                 <fs_knvv>   TYPE knvv.
 
 
* get current pricing table - KNVV
  lv_knvv_tab =  '(SAPLCCCO)GT_KNVV[]' .
  ASSIGN (lv_knvv_tab) TO <fs_knvv_t>.
  CHECK sy-subrc =  0 .
 
* map BAPIMTCS table to complex structure table (partners)
  CALL FUNCTION  'PI_BP_BAPIMTCS_TO_MAIN'
    EXPORTING
      it_bapimtcs               = t_bapistruct[]
    IMPORTING
      et_bp_extern              = lt_complex
      et_not_processed_bapimtcs = lt_not_processed.
 
  LOOP AT lt_complex INTO ls_complex.
    CLEAR: ls_partner, lv_customer.
 
*   set customer
    ls_partner = ls_complex-header-object_instance.
    CALL FUNCTION  'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = ls_partner-bpartner
      IMPORTING
        output = lv_customer.
 
*   go through sales areas of customer
    LOOP AT ls_complex-crm_data-salesarea INTO ls_salesarea.
      CLEAR: lv_vkorg, ls_mtcs_lite.
 
*     set sales organization
      lv_vkorg = ls_salesarea-salesarea-sales_org( 4 ).
 
*     get current pricing data (ABC-classification)
      READ TABLE <fs_knvv_t> ASSIGNING <fs_knvv>
        WITH KEY kunnr = lv_customer
                 vkorg = lv_vkorg
                 vtweg = ls_salesarea-salesarea-channel
                 spart = ls_salesarea-salesarea-division.
      CHECK sy-subrc =  0 .
 
*     add ABC-classification into BAPIMTCS
      DESCRIBE TABLE t_bapistruct[] LINES sy-tfill.
      READ TABLE t_bapistruct INDEX sy-tfill.
      ls_mtcs_lite-currdno = t_bapistruct-currdno +  1 .
      ls_mtcs_lite-objkey  = t_bapistruct-objkey.
      ls_mtcs_lite-relkey  = t_bapistruct-relkey.
 
      CLEAR t_bapistruct.
      MOVE-CORRESPONDING ls_mtcs_lite TO t_bapistruct.
      t_bapistruct-tabname =  'ZMW_PRICING_EXT_S' .
      CONCATENATE lv_customer ls_salesarea-salesarea <fs_knvv>-klabc
        INTO t_bapistruct-data.
      APPEND t_bapistruct.
 
    ENDLOOP.
  ENDLOOP.





Enhancement Steps in CRM

Finding the right place for the "new" field

The ABC classification field does not exist in CRM and must be created first. It should be together with the other customer sales - pricing (billing) data. On the WebUI would that be following: Account Details -> Sales Area Data -> Billing
Technically are the pricing data in the Business Partner Set 0030:

What 

Type 

Name 

Description 

Link between Business Partner and Set 0030 

Table

CRMM_BUT_LNK0031

Business Partner - Billing Rule

Data of Set 0030

Table

CRMM_BUT_SET0030

Business Partner: Billing Data

Data Structure of Set 0030

Structure

CRMT_BUS_SET0030

CRM BP Set Structure for Billing Data

Data X-Structure of Set 0030 

Structure

CRMT_BUS_SET0030X

CRM BP Update Structure for Billing Data

The right place for the ABC classification field is therefore an append structure of structure CRMT_BUS_SET0030.

Create "new" field

I created an append structure called ZMW_PRICING_EXT_S with only field ZZKLABC of type KLABC and added it to CRMT_BUS_SET0030.
I created an other append structure called ZMW_PRICINGX_EXT_S with only field ZZKLABC of type BU_UPDFLAG and added it to CRMT_BUS_SET0030X.

Customizing of User Exit

The CRM Middleware is also enhanced via User Exits on the CRM site. These exits are also triggered by processes which can be found in table TPS01. Unlike in ERP did I find that the processes starting with 'CRM' are not the ones to use but instead those starting with 'SMOUTIL'.
But first a Customer Product is needed - just like in ERP. It is also customized via sm30 of table TBE24.

Product 

ZBPPRIE

 Text

BUPA Pricing Extension

 RFC-destination

 

 Active

X

The actual User Exit is customized via sm30 of table TPS34. The process "user-exit for upload" is the one to use (SMOUTIL3). A new function module needs to be created and the newly added customer product needs to be assigned (through its activation flag is the user-exit called or not).

Process 

SMOUTIL3

 Country

 

 Appl.

 

 Function

Z_CRM_MW_BP_PRICING_IN

 Product

ZBPPRIE 


Function for User Exit

Again it is best to copy the sample function from table TPS01 for the chosen process; in this case SAMPLE_PROCESS_SMOUTIL3.
The TABLES-parameter TI_BAPIMTCS corresponds to T_BAPISTRUCT from ERP and contains all data (tables, structures and fields) that is sent from ERP.

Function Z_CRM_MW_BP_PRICING_IN
*----------------------------------------------------------------------*
* Data defintions -----------------------------------------------------*
*----------------------------------------------------------------------*
  data: lt_complex      type bus_ei_extern_t,
        ls_complex      type bus_ei_extern,
 
        ls_partner      type bus_ei_instance,
        lv_customer     type bu_partner,
        lv_partner_guid type bu_partner_guid,
 
        lv_sales_org    type crmt_sales_org,
        lv_set_guid     type crmt_bu_set_guid,
 
        ls_salesarea    type crmt_bus_ei_salesarea,
        lv_klabc_data   type string,
        begin of ls_klabc_data,
          kunnr type bu_partner.
          include structure crmt_bus_sales_area.
  data:   klabc type klabc,
        end   of ls_klabc_data.
 
 
*----------------------------------------------------------------------*
* Processing ----------------------------------------------------------*
*----------------------------------------------------------------------*
  call function  'CRM_BUPA_BAPIMTCS_TO_MAIN'
    importing
      et_bp_extern              = lt_complex
*      et_not_processed_bapimtcs =
*      et_processed_partner      =
*      et_error_table            =
    changing
      ct_bapimtcs               = ti_bapimtcs[].
 
  check sy-subrc =  0 .
 
  loop at lt_complex into ls_complex.
    clear: ls_partner, lv_customer.
 
*   set customer
    ls_partner = ls_complex-header-object_instance.
    call function  'CONVERSION_EXIT_ALPHA_INPUT'
      exporting
        input  = ls_partner-bpartner
      importing
        output = lv_customer.
 
*   go through sales areas of customer
    loop at ls_complex-crm_data-salesarea into ls_salesarea.
      clear: lv_sales_org, lv_klabc_data, ls_klabc_data, lv_partner_guid, lv_set_guid.
 
*     set sales organization
      lv_sales_org = ls_salesarea-salesarea-sales_org. " save CRM sales org
      clear ls_salesarea-salesarea-sales_org.
      read table ti_bapimtcs with key tabname =  'BSC_SALESA' .
      check sy-subrc =  0 .
      ls_salesarea-salesarea-sales_org = ti_bapimtcs-data( 4 ). " set sales org nr
 
*      try  to get ABC-classification
      concatenate lv_customer ls_salesarea-salesarea  '*'
        into lv_klabc_data.
      loop at ti_bapimtcs where tabname =  'ZMW_PRICING_EXT_S'
                            and data    cp lv_klabc_data.
      endloop.
      check sy-subrc =  0 .
      move ti_bapimtcs-data to ls_klabc_data.
 
*     get guid  for  customer SET  0030  (Pricing)
      lv_partner_guid = ls_partner-bpartnerguid.
      call function  'Z_CRM_BP_GET_0030_SET_GUID'
        exporting
          iv_partner_guid = lv_partner_guid
          iv_sales_org    = lv_sales_org
          iv_channel      = ls_salesarea-salesarea-channel
          iv_division     = ls_salesarea-salesarea-division
        importing
          ev_set_guid     = lv_set_guid.
      check lv_set_guid is not initial.
 
*     update ABC-classification
      update crmm_but_set0030
        set zzklabc = ls_klabc_data-klabc
        where set_guid = lv_set_guid.
 
    endloop.
  endloop.

Adjusting CRM

In the following chapters is the new ABC classification added to the WebUI in CRM. It should be possible to see, change and search for it.

Displaying ABC Classification

Where on the WebUI the field is added i already mentioned. This corresponds to component BP_SALES and View CorpAccountBillingEF.
Because we appended the new field to the official pricing structure is it automatically available when changing the configuration of the named view. So all that is left to do is choose it and put it at wished position onto the view (for the corresponding Role Key).

SAP Standard Change; making a pricing field editable

The above step displays the ABC classification and it is also possible to change the value. But that change is never kept! That is because the pricing fields are handled hardcoded in SAP Standard (which is also why enhancing the view with AET does not work) and thus a new field has to be coded as well.

SAP Standard Objects

Following standard objects are affected by the needed change:

Object 

Name

Description

Function group

CRM_BUPA_CRMC_DIALOG

Dialog Processing of BP Billing Data

Include

LCRM_BUPA_CRMC_DIALOGF06

Implementation of Local Class lcl_fragment_instance_memory

Local Class

lcl_fragment_instance_memory

 

Method

set_set_on

Set Set data with a update fla


Making ABC Classification searchable

Add field to Business Partner Header Search

For being able to choose the ABC classification as a search parameter it has to exist in the BP Header Search Structure CRMT_BUPA_IL_HEADER_SEARCH; I created append structure ZCRM_BP_HEAD_SEARCH_PRICING with field ZZKLABC of type KLABC.
Now it can be added to the configuration of component BP_HEAD_SEARCH view MainSearch.

Programming to search after new field

The BP Header Search logic can be enhanced by implementing BAdI BADI_CRM_BUPA_IL_SEARCH_EXT. This creates following objects:

Object 

Name

Description 

BAdI Implementation

ZBP_SEARCH_PRICING_EXT

Business Partner Search Ext. for Pricing

Implementing Class

ZCL_BP_SEARCH_PRICING_EXT 

Class for BAdI Impl.: ZBP_SEARCH_PRICING_EXT

Method

SEARCH_CRITERIA_INITIAL

Checks if parameters of  this implementation are filled

Method

SEARCH_PARTNERS

Extracts/filters according to the search parameter

The search logic simply checks the ABC classification with the two Set 0030 tables CRMM_BUT_LNK0031 and CRMM_BUT_SET0030.

From CRM to ERP

In the following chapter you'll find the developments done in the ERP and CRM system in order to send the ABC classification of a customer from CRM to ERP.

Enhancement Steps in CRM

Customizing of User Exit

A new User Exit is needed in order to send additional data from CRM to ERP. The same Customer Product as maintained before in table TBE24 can be used. However a new function module for the "user-exit before sending data" process (SMOUTIL2) must be created.

Process 

SMOUTIL2

 Country

 

 Appl.

 

 Function

Z_CRM_MW_BP_PRICING_OUT

 Product

ZBPPRIE 

Function for User Exit

Copy the sample function from table TPS01 for the chosen process; in this case SAMPLE_PROCESS_SMOUTIL2.
Again we're using the TABLES-parameter T_BAPIMTCS to append "our own table" with the ABC-classification (and corresponding customer and sales area) as data.

Function Z_CRM_MW_BP_PRICING_OUT
*----------------------------------------------------------------------*
* Data defintions -----------------------------------------------------*
*----------------------------------------------------------------------*
  data: lt_complex      type bus_ei_extern_t,
        ls_complex      type bus_ei_extern,
 
        ls_partner      type bus_ei_instance,
        lv_customer     type bu_partner,
        lv_partner_guid type bu_partner_guid,
 
        lv_sales_org    type crmt_sales_org,
        lv_set_guid     type crmt_bu_set_guid,
        lv_klabc        type klabc,
 
        ls_salesarea    type crmt_bus_ei_salesarea,
 
        begin of ls_mtcs_lite,
          currdno       type currdno,
          objkey        type crmobjkey,
          relkey        type crmrelkey,
        end   of ls_mtcs_lite.
 
 
*----------------------------------------------------------------------*
* Processing ----------------------------------------------------------*
*----------------------------------------------------------------------*
  call function  'CRM_BUPA_BAPIMTCS_TO_MAIN'
    importing
      et_bp_extern              = lt_complex
*      et_not_processed_bapimtcs =
*      et_processed_partner      =
*      et_error_table            =
    changing
      ct_bapimtcs               = t_bapimtcs[].
 
  check sy-subrc =  0 .
 
  loop at lt_complex into ls_complex.
    clear: ls_partner, lv_customer.
 
*   set customer
    ls_partner = ls_complex-header-object_instance.
    call function  'CONVERSION_EXIT_ALPHA_INPUT'
      exporting
        input  = ls_partner-bpartner
      importing
        output = lv_customer.
 
*   go through sales areas of customer
    loop at ls_complex-crm_data-salesarea into ls_salesarea.
      clear: lv_sales_org, lv_partner_guid, lv_set_guid, lv_klabc, ls_mtcs_lite.
 
*     set sales organization
      lv_sales_org = ls_salesarea-salesarea-sales_org. " save CRM sales org
      clear ls_salesarea-salesarea-sales_org.
      read table t_bapimtcs with key tabname =  'BSC_SALESA' .
      check sy-subrc =  0 .
      ls_salesarea-salesarea-sales_org = t_bapimtcs-data( 4 ). " set sales org nr
 
*     get guid  for  customer SET  0030  (Pricing)
      lv_partner_guid = ls_partner-bpartnerguid.
      call function  'Z_CRM_BP_GET_0030_SET_GUID'
        exporting
          iv_partner_guid = lv_partner_guid
          iv_sales_org    = lv_sales_org
          iv_channel      = ls_salesarea-salesarea-channel
          iv_division     = ls_salesarea-salesarea-division
        importing
          ev_set_guid     = lv_set_guid.
      check lv_set_guid is not initial.
 
*     get ABC-classification from database
      select single
        zzklabc
        into lv_klabc
        from crmm_but_set0030
        where set_guid = lv_set_guid.
      check sy-subrc =  0 .
 
*     add ABC-classification into BAPIMTCS
      describe table t_bapimtcs[] lines sy-tfill.
      read table t_bapimtcs index sy-tfill.
      ls_mtcs_lite-currdno = t_bapimtcs-currdno +  1 .
      ls_mtcs_lite-objkey  = t_bapimtcs-objkey.
      ls_mtcs_lite-relkey  = t_bapimtcs-relkey.
 
      clear t_bapimtcs.
      move-corresponding ls_mtcs_lite to t_bapimtcs.
      t_bapimtcs-tabname =  'ZMW_PRICING_EXT_S' .
      concatenate lv_customer ls_salesarea-salesarea lv_klabc
        into t_bapimtcs-data.
      append t_bapimtcs.
 
    endloop.
  endloop.




SAP Standard Change; triggering replication to ERP for a new pricing field

The triggering of the replication with ERP (meaning noticing a change that should be sent) is again hardcoded for the pricing fields thus needs a change in SAP Standard.

SAP Standard Objects

Following standard objects are affected by the needed change:

Object

Name 

Description

Function group

CRM_BUPA_MWX_BDOC_OUTBOUND

Outbound Processing

Function module 

CRM_BUPA_BDOC_BPS_FILL_DATA

Fill BP Set Structure from Table

Include

LCRM_BUPA_MWX_BDOC_OUTBOUNDF10 

 

Form routine

get_salesarea_segment

Collect sales areas and corresponding Sets

Each time the fields of Set 0030 were hardcoded, I had to add the ABC-classification field (which is five times in total). Only with this change will CRM send the changed ABC-classification to ERP if only that one field was changed -> only then the created user exit is called.

Enhancement Steps in ERP

Customizing of User Exit

A new User Exit is needed in order to handle additional data sent from CRM to ERP. The same Customer Product as maintained before in table TBE24 can be used. However a new function module for the "user-exit for upload" process (CRM0_300) must be created.

Process 

CRM0_300

 Country

 

 Appl.

 

 Function

Z_CRM_MW_BP_PRICING_IN

 Product

ZBPPRIE 


Function for User Exit

Copy the sample function from table TPS01 for the chosen process; in this case SAMPLE_PROCESS_CRM0_300.
Again we're using the TABLES-parameter T_BAPIMTCS to read "our own table" containing the ABC-classification (and corresponding customer and sales area).

Function Z_CRM_MW_BP_PRICING_IN


  DATA: lt_complex            TYPE busei_com_extern_t,
        ls_complex            TYPE busei_com_extern,
        lt_not_processed      TYPE busei_bapimtcs_t,
 
        ls_partner            TYPE busei_com_instance,
        lv_customer           LIKE kna1-kunnr,
 
        ls_salesarea          TYPE busei_ccom_salesarea,
        lv_vkorg              TYPE vkorg,
        lv_klabc_data         TYPE string,
        BEGIN OF ls_klabc_data,
          kunnr               TYPE bu_partner.
          INCLUDE STRUCTURE bsc_salesa.
  DATA:   klabc               TYPE klabc,
        END   OF ls_klabc_data.
 
 
* map BAPIMTCS table to complex structure table (partners)
  CALL FUNCTION  'PI_BP_BAPIMTCS_TO_MAIN'
    EXPORTING
      it_bapimtcs               = t_bapimtcs[]
    IMPORTING
      et_bp_extern              = lt_complex
      et_not_processed_bapimtcs = lt_not_processed.
 
  LOOP AT lt_complex INTO ls_complex.
    CLEAR: ls_partner, lv_customer.
 
*   set customer
    ls_partner = ls_complex-header-object_instance.
    CALL FUNCTION  'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = ls_partner-bpartner
      IMPORTING
        output = lv_customer.
 
*   go through sales areas of customer
    LOOP AT ls_complex-crm_data-salesarea INTO ls_salesarea.
      CLEAR: lv_vkorg, lv_klabc_data, ls_klabc_data.
 
*     set sales organization
      lv_vkorg = ls_salesarea-salesarea-sales_org( 4 ).
 
*      try  to get ABC-classification
      CONCATENATE lv_customer ls_salesarea-salesarea  '*'
        INTO lv_klabc_data.
      LOOP AT t_bapimtcs WHERE tabname =  'ZMW_PRICING_EXT_S'
                           AND data    CP lv_klabc_data.
      ENDLOOP.
      CHECK sy-subrc =  0 .
      MOVE t_bapimtcs-data TO ls_klabc_data.
 
*     update ABC-classification
      UPDATE knvv
        SET klabc = ls_klabc_data-klabc
        WHERE kunnr = lv_customer
          AND vkorg = lv_vkorg
          AND vtweg = ls_klabc_data-channel
          AND spart = ls_klabc_data-division.
 
    ENDLOOP.
  ENDLOOP.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值