二维码

[教程] ENHANCING BP SEARCH WITH EXISTING FIELD

Twilight发表于 2016-02-05 23:07Twilight 最后回复于 2017-03-03 18:46 [复制链接] 7544 2

It is very common requirement to perform a search with the attribute that does not existing in the bp search structure.

For Ex: User wants to find out all business partners whose death date is current date.(Sorry for taking death date as an example)
As we know that death date is a field that exists in BUT000 and assumes that it is not available in selection criteria.

Let us provide search functionality with this new field.

Step1.
Which dynamic query object is used to implement the BP SEARCH?
Ans : Dynamic Query Object ‘BuilHeaderAdvancedSearch’.
enhance bp search 1.jpg

What is the base structure of this query object?
Ans:  Attribute Structure CRMT_BUPA_IL_HEADER_SEARCH.
enhance bp search 2.jpg

So we need to append our new field to this structure in se11 transaction.  Go to the transaction SE11 and append new field to the above structure.
enhance bp search 3.jpg

Save and activate the structure. This makes the newly added field available in the UI configuration in the component BP_HEAD_SEARCH.

Go to this component and view MAINSEARCH configuration and move the new field from available search criteria to the selected search criteria.
enhance bp search 4.jpg

Now we can go to the search page on the WEB UI and we can see the newly added field over there.
enhance bp search 5.jpg

Next we need to create one new implementation for the BADI ‘BADI_CRM_BUPA_IL_SEARCH_EXT’ under enhancement spot ‘CRM_BUPA_IL_SEARCH’.
Go to the transaction se18 and give the above enhancement spot name in the enhancement spot field and click on display.
enhance bp search 6.jpg

Next right click on the BADI ‘BADI_CRM_BUPA_IL_SEARCH_EXT’ and choose the option CREATE BADI implementation.
enhance bp search 7.jpg

It will show already existing enhancement implementations in the next Dialog box. Choose create option.
enhance bp search 8.jpg

Give suitable name and description and leave the last field as blank.
enhance bp search 9.jpg

Once you choose continue, there will be one more dialog box. Here we need give suitable name , description and class name to create BADI implementation. Once you choose continue, then following new implementation will be displayed as below.
enhance bp search 11.jpg

Choose Default implementation check box and Implementation is activate.
Expand the new implementation and double click on implementing class. It will list class methods along with the details.
enhance bp search 12.jpg

Double click on each method and if you receive a message as shown below. Choose Yes.
enhance bp search 13.jpg

Once method implementation is created, activate that method.
We can see the method IF_EX_CRM_BUPA_IL_SEARCH_EXT~SEARCH_CRITERIA_INITIAL. In this method we need to check whether user has filled the newly added field on web ui with any value before he triggers the search.

If user filled it with some value, then we will send one parameter as a TRUE. Based on this value, framework will trigger the next method
IF_EX_CRM_BUPA_IL_SEARCH_EXT~SEARCH_PARTNERS , in which we need to code so that we will get only results which satisfy the criteria with newly added field values.

Double click the IF_EX_CRM_BUPA_IL_SEARCH_EXT~SEARCH_CRITERIA_INITIAL and add the following code and activate the method.
  1. METHOD if_ex_crm_bupa_il_search_ext~search_criteria_initial.

  2.   DATA:ls_bupa_header_search TYPE crmt_bupa_il_header_search.

  3.   MOVE-CORRESPONDING is_parameters TO ls_bupa_header_search.  "set search parameters in search structure
  4.   IF ls_bupa_header_search-zdeathdate IS NOT INITIAL.
  5.     cv_is_not_initial = abap_true.  "...and set the changing parameter to true
  6.   ENDIF.

  7. ENDMETHOD.
复制代码

I am just checking ZDEATHDATE field is filled or not. If it is filled , then I am setting the parameter  CV_IS_NOT_INITIAL as TRUE.

Next double click the method IF_EX_CRM_BUPA_IL_SEARCH_EXT~SEARCH_PARTNERS and add the following code to it and activate the method.
  1. METHOD if_ex_crm_bupa_il_search_ext~search_partners.

  2.   DATA:ls_selection TYPE genilt_selection_parameter,
  3.         ls_keys LIKE LINE OF ct_partner_keys,
  4.         lt_keys TYPE bup_partner_guid_t.

  5.   READ TABLE it_selection_parameters INTO ls_selection WITH KEY attr_name = 'ZDEATHDATE'.
  6.   IF ct_partner_keys IS INITIAL.
  7.     "if query alread fetched some data,then we need to filter the data accordingly.
  8.     SELECT partner partner_guid FROM but000 INTO CORRESPONDING FIELDS OF TABLE ct_partner_keys
  9.       WHERE deathdt = ls_selection-low.
  10.     IF sy-subrc IS NOT INITIAL.
  11.       RAISE no_partners_found.
  12.     ENDIF.
  13.   ENDIF.

  14.   IF ct_partner_keys IS NOT INITIAL.
  15.     "we got the required partners in LT_KEYS. we need only these records.
  16.     SELECT partner partner_guid FROM but000 INTO CORRESPONDING FIELDS OF TABLE lt_keys
  17.       FOR ALL ENTRIES IN ct_partner_keys
  18.       WHERE deathdt = ls_selection-low
  19.       AND partner_guid = ct_partner_keys-partner_guid.
  20.     IF sy-subrc IS NOT INITIAL.
  21.       RAISE no_partners_found.
  22.     ENDIF.
  23.   ENDIF.

  24.   CLEAR ct_partner_keys[].
  25.   ct_partner_keys = lt_keys.

  26. ENDMETHOD.
复制代码

Here there are two cases.

First, user might trigger the search with only new field as selection criteria. In this scenario, no partners will be there in the CT_PARTNER_KEYS. So we just need to return the partner list based on the value in the new field. In this case we need query the table BUT000 based on the DEATH DATE value.
Second, user might trigger search with different fields along with the new field as search criteria.
Ex: list all bps with role as ‘PROSPECT’ and death date as ’20.03.2013’.
In above situation, when control reaches, CT_PARTNER_KEYS will have records of those BPS whose role is PROSPECT. Then we need to select only that Bps, whose death date is 20.03.2013.
That is what we have coded, when CT_PARTNER_KEYS is not initial. In both cases, if sy-subrc is not initial, we are raising the exception of method NO_PARTNER_FOUND.

Next, we have to define the filter value for this BADI implementation. Double click on the Filter Val. Then double click on the COMBINATION and enter the value of the advance search object.
enhance bp search 14.jpg

Now activate the whole implementation.
enhance bp search 15.jpg

Now you can check the BP search by giving some value to the new field DEATH DATE. Then SEARCH PARTNERS method will return the results accordingly. This is very simple implementation. You can include IV_MAX_HIT in the code to control the maximum number of results.
回复

使用道具 举报

lhx7300886
弱弱的问一下,作者你是不是信胡?如果是,那我们可能认识啊,哈哈,请加一下我的qq 289916820
回复 支持 反对

使用道具 举报

Twilight

RE: ENHANCING BP SEARCH WITH EXISTING FIELD

lhx7300886 发表于 2017-3-3 09:14
弱弱的问一下,作者你是不是信胡?如果是,那我们可能认识啊,哈哈,请加一下我的qq 289916820

很遗憾!不是
回复 支持 反对

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表