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.
DATA:ls_selection TYPE genilt_selection_parameter,
ls_keys LIKE LINE OF ct_partner_keys,
lt_keys TYPE bup_partner_guid_t.
READ TABLE it_selection_parameters INTO ls_selection WITH KEY attr_name = 'ZDEATHDATE'.
IF ct_partner_keys IS INITIAL.
"if query alread fetched some data,then we need to filter the data accordingly.
SELECT partner partner_guid FROM but000 INTO CORRESPONDING FIELDS OF TABLE ct_partner_keys
WHERE deathdt = ls_selection-low.
IF sy-subrc IS NOT INITIAL.
RAISE no_partners_found.
ENDIF.
ENDIF.
IF ct_partner_keys IS NOT INITIAL.
"we got the required partners in LT_KEYS. we need only these records.
SELECT partner partner_guid FROM but000 INTO CORRESPONDING FIELDS OF TABLE lt_keys
FOR ALL ENTRIES IN ct_partner_keys
WHERE deathdt = ls_selection-low
AND partner_guid = ct_partner_keys-partner_guid.
IF sy-subrc IS NOT INITIAL.
RAISE no_partners_found.
ENDIF.
ENDIF.
CLEAR ct_partner_keys[].
ct_partner_keys = lt_keys.
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.
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.
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.