Monday, 10 June 2013

61.ENHANCING BP SEARCH WITH EXISTING FIELD



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’.




What is the base structure of this query object?
Ans:  Attribute Structure CRMT_BUPA_IL_HEADER_SEARCH.







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.
 





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. 






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





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. 






Next right click on the BADI ‘BADI_CRM_BUPA_IL_SEARCH_EXT’ and choose the option CREATE BADI implementation.






It will show already existing enhancement implementations in the next dialog box. Choose create option.





Give suitable name and description and leave the last field as blank.






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. 






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.





Double click on each method and if you receive a message as shown below. Choose Yes.





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. 






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. 







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.
 






Now activate the whole implementation.




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.

18 comments:

  1. Many Thanks for your post on my request

    Helped a lot

    Hope to see many documents from you

    -- Dinesh Gurram

    ReplyDelete
  2. we hope it helps you and others as well.

    ReplyDelete
  3. Nice Document. Very helpful. Other than using the BADI's is there any other alternative?

    ReplyDelete
    Replies
    1. hi
      thanks. this is the way to do it for existing field. if it is a totally new field we depend on AET tool.

      Delete
    2. If it's a new field we need to add it using AET for the corresponding business object and we need to Make Search-relavance as Search and Result.

      In this case we no need to implement any BADI right???

      Delete
    3. Yes there is no need to use any badi if we use AET because all structures are enhanced and logic to fetch records will be handled by framework

      Delete
    4. Thank you MANNALA. Your posts were very helpful. Keep up the good work.

      Delete
  4. Thank you Mannala. How did you find Badi here. Is there any way to find suitable Badi in CRM for the perticular requirement.

    ReplyDelete
    Replies
    1. Tthanks there are no exact ways
      Take help from cl exit handler class
      Else break point in debugging at get badi statement
      Last One is spro transaction look for any badis and their documentation

      Delete
  5. Hi Mannala,

    All your blogs has been an immense help for many young developers. So thanks a lot for detail description. However i have a question here. In this dynamic search example you added an existing field and configured it. But does this field available in the dropdown list of existing field in the search without configuring it in the component?

    ReplyDelete
  6. can u please post about use of BP TRANSACTION...
    AND how to use bp transaction
    use of crmd_order
    what is it significance and how to use it

    ReplyDelete
  7. Just a tip: pay attention that the optional IV_MAX_HIT parameter will be unfortunately not filled in by the calling method (see for example CL_BUPA_IL_HEADER_SEARCH=>FILTER_BY_SEARCH_CRITERIA)
    if you than search ony by the z-fields, it will be perform a full search on the db. sap meant that the filtern on the max hit will be performed later. In my opinion it is bug. Best Regards. Diego

    ReplyDelete
  8. Hi Praveen,

    If suppose there are 10 new fields to be added to Account Search, then is it better way to create 10 AET fields? Or can we create a Z-Class with cuper class as CL_BUPA_IL_HEADER_SEARCH & maintain it for object name BuilHeaderAdvancedSearch in SPRO->CRM Cross Application component-> Genil Interaction layer/Object layer->Extend object model for business partner in SPRO and then implement a single dynamic select query for these 10 fields????
    Please suggest...... Sameena ;)

    ReplyDelete
    Replies
    1. scenario 1
      fields are already available in the database but not available in the search.
      then we can go with the second approach. No need of AET.

      if fileds are not avaiable in the database, then AET is will be the best option.
      Please let me know if you have second thoughts.

      Delete
  9. Hi Praveen,

    Just to make a point here... If suppose we are searching for field PERSNUMBER which is available in BUT000 table but not in the structure CRMT_BUPA_IL_HEADER_SEARCH, and if we enhance the structure & BADI as described above, then there can be chances of performance issue here.

    If the search is performed with any field like country along with persnumber, then the badi receives 500 entries (if max hit is 500) as input for the search performed on country field in changing parameters. Then it finds for the partner which is obtained for PERSNUMBER among the 500 entries, then there is a chance that the partner that we are searching for may not be in the 500 entries, may be among 700 or so... but as we get only max hit entries in changing parameter chances are that we may not find the entry though there is an entry for persnumber in BUT000 table.

    If suppose we remove this max hit, then we get 'n' entries in changing parameter of badi for country, and then searching for one partner which obtained from persnumber among 'n' entries is may lead to performance issue.

    ---- Sameena

    ReplyDelete
    Replies
    1. Nice one. Yeah that can happen. we need to remove the max hits before making a call to the standard FM. Then it will fetch all possible entries.

      Delete
  10. Hello Mannala,
    Many Thanks for your wonderful post.
    But i have 1 query to be resolved regarding this article:

    Suppose you want to enhance the Search Query Object and the new field you want to add in the search criteria and the new field is already available in one of the CRM tables (as in your article) and not in Search Object Attributes, then what would be the best approach to enhance the Search Query object and why and if not, then why?

    1) Enhancing the Search object attribute structure in SE11 and then find the appropriate BADI implementation for writing the search logic for new field?

    2) Creating Model/Value Attribute in the Search Object thorugh Component Worknbench and then enhancing the EH_ONSEARCH method to add the search logic for new attribute?

    3) Creating the new field through AET and enhance the appropriate BADI?

    ReplyDelete
  11. would like to know, how to increase the number of results being displayed for a particular role, as i want to maintain this on a global level. I did find out that we can customize the number of rows before scrolling and other parameters. But each and every user has to set it, so i want to make this global as a default for only people with certain roles, how can i do this? tks

    ReplyDelete