# Created by Jerry Wang on Mar 08, 20141. Enter the search page of Product:2. Enter the background ST12 Transaction Code, set task type to HTTP, and click Start Trace button:I’m going to hit the Search button on the UI and when I see the search result, I’m going to hit End Trace:3. Click ABAP trace to view trace:Sort by Net time so that method/Function Module calls that take longer to execute are displayed at the top:Select row and press CTRL +F7 or Menu goto->Display Source Code to see the corresponding ABAP code:For example, why is this method called 1800 times? We can set a breakpoint inside the method and hit the Search button to trigger the breakpoint,By observing the callstack, it can be found that for each product, each field of the structure comt_product_UI should be traversed:This structure has a total of 18 fields, and our search Max hit is set to 100, resulting in 1800 calls.

 

 

i042416 added the CRM Product label on Oct 4, 2017

Owner Author

i042416 commented on Oct 4, 2017

| # 创建新的product search scenario## Created by Jerry Wang on May 28, 2014根据UI上的partner ID和Object description这两个search parameter专门创建search scenario: 使用如下report消费该search scenario:“`html DATA: lt_option TYPE comt_prsearch_gen_tab. DATA: lt_product TYPE comt_prsearch_selection_tab. DATA: lt_return TYPE bapiret2_tab. DATA: ls_return TYPE bapiret2. DATA: ls_product TYPE LINE OF comt_prsearch_selection_tab. DATA: ls_option TYPE comt_prsearch_gen. ls_option-frgtype_id = ‘COMM_PR_SHTEXT’. ls_option-attribute = ‘SHORT_TEXT’. ls_option-sign = ‘I’. ls_option-option = ‘EQ’. ls_option-low = ‘object mass created of 200124’. ls_option-high = space. INSERT ls_option INTO TABLE lt_option. ls_option-frgtype_id = ‘SAP_IL_PRDBP’. ls_option-attribute = ‘DESTINGUID’. ls_option-sign = ‘I’. ls_option-option = ‘EQ’. ls_option-low = ‘B5B05A3007CCD411917708000627B381’. ls_option-high = space. INSERT ls_option INTO TABLE lt_option. CALL FUNCTION ‘COM_PRODUCT_GETLIST_API’ EXPORTING it_gen_sel_options = lt_option iv_scenario = ‘ZCL_NEW_SCENARIO_AFTER_OPT’ iv_request_data = ‘X’ IMPORTING et_product = lt_product et_bapireturn = lt_return EXCEPTIONS no_scenario = 1 error_getlist = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. LOOP AT lt_return INTO ls_return. WRITE: / ls_return-message. ENDLOOP. LOOP AT lt_product INTO ls_product. WRITE: / ls_product-product_guid. ENDLOOP. WRITE: / ‘Finished’. 新的search scenario class需要继承CL_COM_PRSEARCHSCENARIO_BASE,代码如下: class ZCL_NEW_SCENARIO_AFTER_OPT definition public inheriting from CL_COM_PRSEARCHSCENARIO_BASE final create public . public section. protected section. methods DETERMINE_STANDARD_TOOL redefinition . private section. ENDCLASS. CLASS ZCL_NEW_SCENARIO_AFTER_OPT IMPLEMENTATION. * —————————————————————————————+ * | Instance Protected Method ZCL_NEW_SCENARIO_AFTER_OPT->DETERMINE_STANDARD_TOOL * +————————————————————————————————-+ * | [—>] IT_CRITERIA TYPE COMT_PRSEARCH_CRITERIA_TAB * | [<—] EI_TOOL TYPE REF TO IF_COM_PRSEARCHTOOL * | [<—] ET_FILTER TYPE COMT_PRSEARCH_FILTER_TAB * | [EXC!] NO_STANDARD_TOOL_FOUND * | [EXC!] ERROR * +————————————————————————————– method DETERMINE_STANDARD_TOOL. DATA: lr_filter TYPE REF TO if_com_prsearchfilter. DATA: lr_tool TYPE REF TO if_com_prsearchtool. CREATE OBJECT lr_tool TYPE ZCL_NEW_SEARCH_TOOL_AFTER_OPT. ei_tool = lr_tool. CREATE OBJECT lr_filter TYPE ZCL_NEW_FILTER_AFTER_OPT. INSERT lr_filter INTO TABLE et_filter. endmethod. ENDCLASS. filter class负责检测在何种search parameter的组合情况下对应的search tool class会被使用: class ZCL_NEW_FILTER_AFTER_OPT definition public final create public . public section. interfaces IF_COM_PRSEARCHFILTER . protected section. private section. ENDCLASS. CLASS ZCL_NEW_FILTER_AFTER_OPT IMPLEMENTATION. * —————————————————————————————+ * | Instance Public Method ZCL_NEW_FILTER_AFTER_OPT->IF_COM_PRSEARCHFILTERFILTER * +————————————————————————————————-+ * | [—>] IV_LANGUAGE TYPE SPRAS (default =SY-LANGU) * | [—>] IT_CRITERIA TYPE COMT_PRSEARCH_CRITERIA_TAB * | [<–>] CT_DATA TYPE COMT_PRSEARCH_DATA_TAB(optional) * | [<–>] CT_SELECTION TYPE COMT_PRODUCT_GUID_T * | [EXC!] ERROR * +————————————————————————————– method IF_COM_PRSEARCHFILTERFILTER. endmethod. * —————————————————————————————+ * | Instance Public Method ZCL_NEW_FILTER_AFTER_OPT->IF_COM_PRSEARCHFILTERRELEVANT_CRITERIA * +————————————————————————————————-+ * | [—>] IV_CRITERION TYPE COMT_PRSEARCH_CRITERION * | [<—] EV_COVERED TYPE COMT_BOOLEAN * +————————————————————————————– method IF_COM_PRSEARCHFILTERRELEVANT_CRITERIA. IF iv_criterion-frgtype_id = ‘COMM_PR_SHTEXT’ OR iv_criterion-frgtype_id CP ‘SAP_IL_‘. ev_covered = ‘X’. ENDIF. endmethod. ENDCLASS. search tool class则负责进行真正的搜索: class ZCL_NEW_SEARCH_TOOL_AFTER_OPT definition public final create public . public section. interfaces IF_COM_PRSEARCHTOOL . protected section. private section. types: BEGIN OF ty_bp_range, sign TYPE BAPISIGN, option TYPE BAPIOPTION, low TYPE COMT_IL_DESTINGUID, high type COMT_IL_DESTINGUID, end of ty_bp_range . types: tt_bp_range TYPE STANDARD TABLE OF ty_bp_range . types: BEGIN OF ty_text_range, sign TYPE BAPISIGN, option TYPE BAPIOPTION, low TYPE COMT_PRSHTEXTX, high type COMT_PRSHTEXTX, end of ty_text_range . types: tt_text_range TYPE STANDARD TABLE OF ty_text_range . data MT_BP_RANGE type TT_BP_RANGE . data MT_TEXT_RANGE type TT_TEXT_RANGE . methods DO_READ_SHTEXT importing !IV_LANGUAGE type SPRAS changing !CT_RESULT type ANY TABLE exceptions ERROR . methods BUILD_IN_TABLE importing !IT_CRITERIA type COMT_PRSEARCH_CRITERIA_TAB . ENDCLASS. CLASS ZCL_NEW_SEARCH_TOOL_AFTER_OPT IMPLEMENTATION. * —————————————————————————————+ * | Instance Private Method ZCL_NEW_SEARCH_TOOL_AFTER_OPT->BUILD_IN_TABLE * +————————————————————————————————-+ * | [—>] IT_CRITERIA TYPE COMT_PRSEARCH_CRITERIA_TAB * +————————————————————————————– method BUILD_IN_TABLE. DATA: ls_criteria LIKE LINE OF it_criteria, ls_bp_range LIKE LINE OF mt_bp_range, ls_text_range LIKE LINE OF mt_text_range, ls_option LIKE LINE OF ls_criteria-options. READ TABLE it_criteria INTO ls_criteria WITH KEY FRGTYPE_ID = ‘SAP_IL_PRDBP’ ATTRIBUTE = ‘DESTINGUID’. CHECK sy-subrc = 0. READ TABLE ls_criteria-options INTO ls_option INDEX 1. CHECK sy-subrc = 0. ls_bp_range-low = ls_option-low. ls_bp_range-sign = ‘I’. ls_bp_range-option = ‘EQ’. APPEND ls_bp_range TO mt_bp_range. READ TABLE it_criteria INTO ls_criteria WITH KEY FRGTYPE_ID = ‘COMM_PR_SHTEXT’ ATTRIBUTE = ‘SHORT_TEXT’. CHECK sy-subrc = 0. READ TABLE ls_criteria-options INTO ls_option INDEX 1. CHECK sy-subrc = 0. ls_text_range-sign = ‘I’. ls_text_range-option = ‘EQ’. ls_text_range-low = ls_option-low. APPEND ls_text_range TO mt_text_range. endmethod. * —————————————————————————————+ * | Instance Private Method ZCL_NEW_SEARCH_TOOL_AFTER_OPT->DO_READ_SHTEXT * +————————————————————————————————-+ * | [—>] IV_LANGUAGE TYPE SPRAS * | [<–>] CT_RESULT TYPE ANY TABLE * | [EXC!] ERROR * +————————————————————————————– METHOD DO_READ_SHTEXT . FIELD-SYMBOLS: <product_guid> TYPE comt_product_guid. FIELD-SYMBOLS: <short_text> TYPE comt_prshtextx. FIELD-SYMBOLS: TYPE spras. FIELD-SYMBOLS: TYPE ANY. DATA: lt_product TYPE comt_product_tab. DATA: ls_product TYPE comt_product. DATA: lt_shtext TYPE comt_prshtext_tab. DATA: ls_shtext TYPE comt_prshtext. * Get the product GUIDs LOOP AT ct_result ASSIGNING . ASSIGN (‘-PRODUCT_GUID’) TO <product_guid>. IF sy-subrc <> 0. RAISE error. ENDIF. ls_product-product_guid = <product_guid>. INSERT ls_product INTO TABLE lt_product. ENDLOOP. * mass read for short text CALL FUNCTION ‘COM_COMM_PR_SHTEXT_READ_MULTIP’ EXPORTING it_product = lt_product iv_update_buffer = space iv_all_langu = space iv_langu = iv_language IMPORTING et_set = lt_shtext. * Insert short text into result table LOOP AT ct_result ASSIGNING . ASSIGN (‘-PRODUCT_GUID’) TO <product_guid>. IF sy-subrc <> 0. RAISE error. ENDIF. ASSIGN (‘-SHORT_TEXT’) TO <short_text>. IF sy-subrc <> 0. RAISE error. ENDIF. ASSIGN (‘-LANGU’) TO . IF sy-subrc <> 0. RAISE error. ENDIF. * get short text and copy the result data READ TABLE lt_shtext INTO ls_shtext WITH KEY product_guid = <product_guid>. CHECK sy-subrc = 0. <short_text> = ls_shtext-short_text. = iv_language. ENDLOOP. ENDMETHOD. * —————————————————————————————+ * | Instance Public Method ZCL_NEW_SEARCH_TOOL_AFTER_OPT->IF_COM_PRSEARCHTOOLGETLIST_ACTIVE * +————————————————————————————————-+ * | [—>] IV_MAX_ROWS TYPE BAPIMAXROW (default =0) * | [—>] IV_LANGUAGE TYPE SPRAS (default =SY-LANGU) * | [—>] IT_CRITERIA TYPE COMT_PRSEARCH_CRITERIA_TAB * | [—>] II_SCENARIO TYPE REF TO CL_COM_PRSEARCHSCENARIO_BASE(optional) * | [—>] IV_REQUEST_DATA TYPE COMT_BOOLEAN (default =SPACE) * | [<—] ET_SELECTION TYPE COMT_PRSEARCH_SELECTION_TAB * | [<—] ET_DATA TYPE COMT_PRSEARCH_DATA_TAB * | [EXC!] ERROR * +————————————————————————————– method IF_COM_PRSEARCHTOOLGETLIST_ACTIVE. DATA: lv_cursor TYPE cursor , lv_finished TYPE comt_boolean , lt_product TYPE STANDARD TABLE OF comt_prsearch_selection , ls_product_all TYPE comt_prsearch_selection , lt_product_all TYPE STANDARD TABLE OF comt_prsearch_selection , ls_criteria TYPE comt_prsearch_criterion, ls_option LIKE LINE OF ls_criteria-options, ls_selection LIKE LINE OF et_selection, lv_index_low TYPE i, lv_index_high TYPE i, lv_result_count TYPE i, lt_bp_range TYPE tt_bp_range, ls_bp_range TYPE ty_bp_range, ls_text_range TYPE ty_text_range, lt_text_range TYPE tt_text_range. CALL METHOD build_in_table EXPORTING it_criteria = it_criteria. OPEN CURSOR WITH HOLD lv_cursor FOR SELECT pproduct_guid plogsys pproduct_id pproduct_type pconfig pxnosearch pobject_family pbatch_dedicated pcompetitor_prod FROM COMM_PRODUCT AS P INNER JOIN COMM_IL_PRDBP AS Q ON PPRODUCT_GUID = QSOURCEGUID INNER JOIN COMM_PRSHTEXT AS J ON PPRODUCT_GUID = JPRODUCT_GUID CLIENT SPECIFIED WHERE Pclient = sy-mandt AND QDESTINGUID IN mt_bp_range AND JSHORT_TEXT IN mt_text_range. WHILE lv_finished = space. FETCH NEXT CURSOR lv_cursor INTO CORRESPONDING FIELDS OF TABLE lt_product PACKAGE SIZE 100. IF sy-subrc = 0. CALL METHOD cl_com_prsearch_util=>execute_filter_selection EXPORTING iv_max_rows = iv_max_rows ir_scenario = ii_scenario IMPORTING ev_max_rows_reached = lv_finished CHANGING ct_result = lt_product_all ct_selection = lt_product. ELSE. EXIT. ENDIF. ENDWHILE. CLOSE CURSOR lv_cursor. LOOP AT lt_product_all INTO ls_product_all. MOVE-CORRESPONDING ls_product_all TO ls_selection. INSERT ls_selection INTO TABLE et_selection. ENDLOOP. IF NOT iv_request_data IS INITIAL. CALL METHOD do_read_shtext EXPORTING iv_language = iv_language CHANGING ct_result = et_selection EXCEPTIONS OTHERS = 0. ENDIF. endmethod. * —————————————————————————————+ * | Instance Public Method ZCL_NEW_SEARCH_TOOL_AFTER_OPT->IF_COM_PRSEARCHTOOLRELEVANT_CRITERIA * +————————————————————————————————-+ * | [—>] IV_CRITERION TYPE COMT_PRSEARCH_CRITERION * | [<—] EV_COVERED TYPE COMT_BOOLEAN * +————————————————————————————– method IF_COM_PRSEARCHTOOLRELEVANT_CRITERIA. CLEAR ev_covered. IF iv_criterion-frgtype_id = ‘COMM_PR_SHTEXT’ OR iv_criterion-frgtype_id CP ‘SAP_IL_‘. ev_covered = ‘X’. ENDIF. IF iv_criterion-frgtype_id = cl_com_prsearch_util=>frgid_product AND ( iv_criterion-attribute = cl_com_prsearch_util=>attr_batch_dedicated OR iv_criterion-attribute = cl_com_prsearch_util=>attr_competitor_product OR iv_criterion-attribute = cl_com_prsearch_util=>attr_config OR iv_criterion-attribute = cl_com_prsearch_util=>attr_logsys OR iv_criterion-attribute = cl_com_prsearch_util=>attr_object_family OR iv_criterion-attribute = cl_com_prsearch_util=>attr_product_id OR iv_criterion-attribute = cl_com_prsearch_util=>attr_product_type OR iv_criterion-attribute = cl_com_prsearch_util=>attr_locked ). ev_covered = ‘X’. ENDIF. endmethod. ENDCLASS.

| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Copy the code