*Get the BOL Core instance
DATA: lr_core1 TYPE REF TO cl_crm_bol_core.
*Load the component set Or Component
lr_core1 = cl_crm_bol_core=>get_instance( ).
lr_core1->start_up( 'BP_APPL' ).
*Determine Dynamic Query Services Available
DATA:lv_obj_model TYPE REF TO if_genil_obj_model.
lv_obj_model = cl_crm_genil_model_service=> get_runtime_model( ).
DATA:lt_query_names TYPE crmt_ext_obj_name_tab.
CALL METHOD lv_obj_model->get_object_list
EXPORTING
iv_object_kind = if_genil_obj_model=>dquery_ object
* iv_ws_enabled_only = ABAP_FALSE
IMPORTING
et_object_list = lt_query_names.
**Select Particular Query
DATA:lv_query_name TYPE crmt_ext_obj_name.
READ TABLE lt_query_names INTO lv_query_name INDEX 6. "'BuilContactAdvancedSearch '
*Create Query Service by passing the dynamic search object name
DATA:lv_query TYPE REF TO cl_crm_bol_dquery_service.
lv_query = cl_crm_bol_dquery_service=> get_instance( lv_query_name ).
*Set General Query parameters for maximum number of hits
DATA lt_parms TYPE crmt_name_value_pair_tab.
DATA ls_parms TYPE crmt_name_value_pair.
ls_parms-name = 'MAX_HITS'.
ls_parms-value = '5'.
APPEND ls_parms TO lt_parms.
lv_query->set_query_ parameters( it_parameters = lt_parms ).
*Add Selection Criteria where BP number > 30
CALL METHOD lv_query->add_selection_param
EXPORTING
iv_attr_name = 'BP_NUMBER'
iv_sign = 'I'
iv_option = 'GT'
iv_low = '0000311966' "0000311966
iv_high = ' '.
*Execute Query and Receive Result
DATA:lv_result_tab TYPE REF TO if_bol_entity_col. "To Capture Multiple Records
lv_result_tab = lv_query->get_query_result( ).
lv_result_tab->sort( iv_attr_name = 'BP_NUMBER'
iv_sort_order = if_bol_bo_col=>sort_descending ).
*Use Iterator to access entities in query result
DATA:lv_iterator TYPE REF TO if_bol_entity_col_iterator. "or IF_BOL_ENTITY_COL
lv_iterator = lv_result_tab->get_iterator( ).
DATA:lv_bp TYPE REF TO if_bol_bo_property_access. "CL_CRM_BOL_ENTITY
lv_bp = lv_iterator->find_by_property( iv_attr_name = 'BP_NUMBER'
iv_value = '0000406648' ).
DATA:lv_bp_find TYPE REF TO cl_crm_bol_entity.
lv_bp_find ?= lv_bp.
lv_bp_find = lv_result_tab->find( iv_entity = lv_bp_find ).
*Get First Entity in the result list.
*Entity is contact person here.
DATA:lv_entity TYPE REF TO cl_crm_bol_entity.
lv_entity = lv_iterator->get_first( ).
*Loop through Further Entities....
WHILE lv_entity IS BOUND. "If lv_entity is not initial..
*Access Attributes of the Business Object (Entity) Selected
DATA:lv_bpnumber TYPE string,
lv_contactbp TYPE string.
lv_bpnumber = lv_entity->get_property_as_ string( 'BP_NUMBER' ).
lv_contactbp = lv_entity->get_property_as_ string( 'CONP_NUMBER' ).
WRITE: / lv_bpnumber.
lv_entity = lv_iterator->get_next( ).
ENDWHILE.
Thanks for Information SAP Online Training
ReplyDeleteNice blog with good explanation on SAP Training modules..
ReplyDeleteVery good explanation on SAP CRM concepts we do SAP Training in Chennai for all SAP Modules.
ReplyDeleteThanks for sharing this Information. SAP CRM Training Institute in Gurgaon
ReplyDelete