Skip to Content
0

Error in Search ?

Sep 11, 2017 at 09:10 AM

58

avatar image

Hello Experts,

I created Custom UI Component to display employee details, I created some records and when i want to search records.

by giving any name and clicking on search, it was throwing error.

My API Code search code is

and read code is.

and my Custom Genil Class method code is.

METHOD if_genil_appl_intlay~get_dynamic_query_result.

DATA : lr_msg_cont TYPE REF TO cl_crm_genil_global_mess_cont,
lv_num_hits TYPE i,
lt_results TYPE ybol_empl_master_key_tab,
lv_max_hits TYPE char5,
lv_max_hits_tmp TYPE int4,
lr_root_object TYPE REF TO if_genil_cont_root_object,
lt_request_obj TYPE crmt_request_obj_tab.

FIELD-SYMBOLS: <fs_results> TYPE ybol_empl_master_key.

* Retrieve the message container to log eventual messages
lr_msg_cont = iv_root_list->get_global_message_container( ).

** * When the max hits is set to 0.
IF is_query_parameters-max_hits IS INITIAL.
lv_max_hits_tmp = 100. "100 when no max_hits is set
ELSE.
lv_max_hits_tmp = is_query_parameters-max_hits.
ENDIF.

* select the rigth query
CASE iv_query_name.

WHEN 'SearchEmployees'.


CALL METHOD search_employee
EXPORTING
it_search_creteria = it_selection_parameters
iv_max_hits = lv_max_hits_tmp
IMPORTING
et_results = lt_results.

IF lt_results IS NOT INITIAL.
* Log a message if search result exceed the max hit limit
DESCRIBE TABLE lt_results LINES lv_num_hits.
IF lv_num_hits > lv_max_hits_tmp.
lv_max_hits = lv_max_hits_tmp.
lr_msg_cont->add_message( iv_msg_type = 'I'
iv_msg_id = 'ZMESSAGES'
iv_msg_number = '001'
iv_msg_v1 = lv_max_hits
iv_show_only_once = abap_true ).

ENDIF.

* Loop through the results to build search result objects
LOOP AT lt_results ASSIGNING <fs_results>.
TRY.


* Try to create a new result object
lr_root_object = iv_root_list->add_object(
iv_object_name = 'Employee'
is_object_key = <fs_results> ).


* Flag it as direct query result
lr_root_object->set_query_root( abap_true ).
CATCH cx_crm_genil_duplicate_rel cx_crm_genil_model_error.

* Since the given object name is correct this could not happen!
ENDTRY.
ENDLOOP.

* Note: The request object restricts the attributes to read.
* If there is no request object entry or the attributes
* table is empty all attributes are requested.
* read the attributes and relation using the GET_OBJECTS
me->if_genil_appl_intlay~get_objects( it_request_objects = lt_request_obj
iv_root_list = iv_root_list ).
ELSE.
lr_msg_cont->add_message( iv_msg_type = 'W'
iv_msg_id = 'ZMESSAGES'
iv_msg_number = '002'
iv_show_only_once = abap_true ).
ENDIF.
WHEN OTHERS.
RETURN.
ENDCASE.

ENDMETHOD.

AND ANOTHER METHOD IS.

method IF_GENIL_APPL_INTLAY~GET_OBJECTS.

DATA: lv_root TYPE REF TO if_genil_cont_root_object,
lv_key TYPE ybol_empl_master_key,
lv_empl_att TYPE ybol_employee_details_attr.

********* Get the first object of data container.

lv_root = iv_root_list->get_first( ).

lv_root->get_key( IMPORTING es_key = lv_key ).

********** Check if attributes are read after Create

IF lv_root->check_attr_requested( ) = abap_true.

********* Custom API class to get the customer attributes.

zhcl_empl_details_api=>read_employee( EXPORTING is_empl_key = lv_key
IMPORTING es_empl_attr = lv_empl_att ).


********* Return the objects only if it exists
IF lv_empl_att IS NOT INITIAL.

******** Set the attributes in container
lv_root->set_attributes( lv_empl_att ).

******* Get the next object of data container.

lv_root = iv_root_list->get_next( ).

ENDIF.
ENDIF.
endmethod.

another method in Genil class which was to search employee is.

method SEARCH_EMPLOYEE.

DATA: lv_max_hits TYPE i,
lv_string TYPE string,
lt_search_criteria TYPE genilt_selection_parameter_tab,
lv_last_attr_name TYPE name_komp.

FIELD-SYMBOLS: <search_criteria> TYPE genilt_selection_parameter.

* NOTE:
* This is a good place to implement Authority checks!!!
*
lv_max_hits = iv_max_hits.
IF lv_max_hits EQ 0.
lv_max_hits = 100.
ENDIF.

lt_search_criteria = it_search_creteria.

SORT lt_search_criteria BY attr_name.

LOOP AT lt_search_criteria ASSIGNING <search_criteria>.

* NOTE: * The current implementation takes care only of CP and EQ search criteria options.
IF ( <search_criteria>-option EQ 'EQ' OR <search_criteria>-option EQ 'CP' ).

IF lv_string IS NOT INITIAL.

IF <search_criteria>-attr_name NE lv_last_attr_name.

CONCATENATE lv_string ')AND(' INTO lv_string SEPARATED BY space.
ELSE.
CONCATENATE lv_string 'OR' INTO lv_string SEPARATED BY space.
ENDIF.

ELSE.
lv_string = '('.
ENDIF.


CONCATENATE lv_string <search_criteria>-attr_name <search_criteria>-option '' INTO lv_string SEPARATED BY space.
CONCATENATE lv_string <search_criteria>-low INTO lv_string.
CONCATENATE lv_string '' INTO lv_string.
ENDIF.

lv_last_attr_name = <search_criteria>-attr_name.
ENDLOOP.

REFRESH et_results.

IF lv_string IS NOT INITIAL.

CONCATENATE lv_string ')' INTO lv_string SEPARATED BY space.
ENDIF.

* retrieve data from the backend
CALL METHOD zhcl_empl_details_api=>search_employee( EXPORTING iv_string = lv_string
iv_max_hits = lv_max_hits
IMPORTING et_results = et_results ).


endmethod.

ABOVE Mentioned was all methods attached to Search could you please refer it and suggest me solution.

When i did debugged i got an error cx_sy_no_handler.

ujp8o.jpeg (75.8 kB)
xpuxy.jpeg (34.0 kB)
cgdcl.jpeg (66.6 kB)
jo6bf.jpeg (47.5 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Varun Agarwal
Sep 12, 2017 at 12:20 PM
0

Hi Harish,

Based on the logic written by you, your SELECT query is SELECT employee_id guid FROM yempl_details UP TO iv_max_hits ROWS INTO CORRESPONDING FIELDS OF TABLE et_results WHERE (iv_string)

iv_string would contain HARISH and therefore, the clause SELECT employee_id ...... WHERE HARISH does not make any sense and thats why it is throwing an error.

Whenever WHERE Clause is used, there should be operator or condition that is fulfilled.

You can refer to the coding in Method DETERMINE_EXIT_CRITERIA of Class CL_BUPA_IL_SEARCH_SERVICE and method FILTER_BY_SEARCH_CRITERIA of class CL_BUPA_IL_CP_SEARCH in standard SAP CRM to know how exactly the coding should be.

Best Regards,
Varun Agarwal

Share
10 |10000 characters needed characters left characters exceeded