Skip to Content

There are two main types of objects in the BOL: business objects (entities) and query services. You can find an overview of the available query services and BOL objects in the BOL browser (Transaction GENIL_MODEL_BROWSER). You can use query services to search for specific business objects within the BOL. A query service is represented by a query object, which is managed by a Query Manager (also an object).The BOL Browser (Transaction GENIL_BOL_BROWSER) can be used to test the query services and BOL objects.

There are two types of query objects: a) Query Objects and b) Dynamic Query Objects. In this document I am going to illustrate two examples to use query objects in BOL programming:

Query Objects

Here is the testing screen for normal query objects where we can pass the values for query parameters and execute the query.

1.JPG

The handler class for query objects: CL_CRM_BOL_QUERY_SERVICE. The methods mentioned in this class can be used to execute a business query. Here are the steps:

Step1: Create an instance of the query object using the method GET_INSTANCE of the handler class.

Pass the name of the query object to importing parameter IV_QUERY_NAME.

DATA:   lr_queryservice TYPE REF TO cl_crm_bol_query_service.

                              TRY.

    CALL METHOD cl_crm_bol_query_service=>get_instance

       EXPORTING

         iv_query_name = ProdAdvancedSearchCompetProds

       RECEIVING

         rv_result     = lr_queryservice.

    CATCH cx_crm_unsupported_object.

                              ENDTRY.

Step2: Set the query parameters using method SET_QUERY_PARAMETERS of the handler class. Pass the parameters to the importing parameter IT_PARAMETERS. IT_PARAMETERS is an internal table with two fields name and value.

DATA:   lt_parameters    TYPE        crmt_name_value_pair_tab,
             ls_parameters   
TYPE        crmt_name_value_pair.

***Fill the internal table with parameter name and values entries based on which query will be executed

ls_parameters-name = ‘OBJECT_FAMILY’.
ls_parameters-value =
‘0401’.

APPEND ls_parameters TO lt_parameters.

CALL METHOD lr_queryservice->set_query_parameters
 
EXPORTING
    it_parameters = lt_parameters
    iv_convert    = abap_true.

Step3: After we set the query object parameters we can use the method GET_QUERY_RESULT of the handler class to get the query result as a collection of entities.

DATA:   lr_queryresult   TYPE REF TO if_bol_entity_col.

CALL METHOD lr_queryservice->get_query_result
 
RECEIVING          
    rv_result = lr_queryresult.

Step4: From this collection of entities we can loop through to read the value of the required attribute e.g.

DATA:   lr_objdesc                   TYPE REF TO cl_crm_bol_entity,
             lv_object_family_desc
TYPE string.

CHECK lr_queryresult IS BOUND.

CALL METHOD lr_queryresult->get_first
 
RECEIVING
    rv_result = lr_objdesc.

CHECK lr_objdesc IS BOUND.

CALL METHOD lr_objdesc->if_bol_bo_property_access~get_property_as_value
 
EXPORTING
    iv_attr_name =
‘OBJECT_FAMILY_DESC’
 
IMPORTING
    ev_result    = lv_object_family_desc.

Note: If we want to access the query objects in report program we need to add the following lines of code

DATA:   lr_core               TYPE REF TO cl_crm_bol_core.

lr_core = cl_crm_bol_core=>get_instance( ).

lr_core->start_up(‘ALL’).

Dynamic Query Objects

Here is the testing screen for dynamic query objects. We need to add the selection parameters explicitly here. We can also maintain the query parameters like Max Hits, Match Type etc.

2.JPG

The handler class for query objects: CL_CRM_BOL_DQUERY_SERVICE. The methods mentioned in this class can be used to execute a business query. Here are the steps:

Step1: Create an instance of the query object using the method GET_INSTANCE of the handler class.

Pass the name of the query object to importing parameter IV_QUERY_NAME.

DATA:   lr_queryservice TYPE REF TO cl_crm_bol_dquery_service.

                              TRY.

    CALL METHOD cl_crm_bol_dquery_service=>get_instance

       EXPORTING

         iv_query_name = PrCategoryAdvSrch

       RECEIVING

         rv_result     = lr_queryservice.

    CATCH cx_crm_unsupported_object.

                              ENDTRY.

Step2: In this step we need to maintain the query selection parameters. As we can see from the model browser test screen, there are no predefined selection parameters whose value we can set as we did in the earlier case. Here we need to add selection parameters. Use method ADD_SELECTION_PARAM of the handler class to add the selection parameters

CHECK lr_queryservice IS BOUND.

CALL METHOD lr_queryservice->add_selection_param

      EXPORTING

        iv_attr_name = ‘OBJECT_FAMILY’

        iv_sign      = ‘I’

        iv_option    = ‘EQ’

        iv_low       = ‘0401’

        iv_high      = .

Step3: After we add the query object selection parameters we can use the method GET_QUERY_RESULT of the handler class to get the query result as a collection of entities.

DATA:   lr_queryresult   TYPE REF TO if_bol_entity_col.

CALL METHOD lr_queryservice->get_query_result
 
RECEIVING          
    rv_result = lr_queryresult.

Step4: From this collection of entities we can loop through to read the value of the required attribute e.g.

DATA:   lr_category                  TYPE REF TO cl_crm_bol_entity,
             lv_category                 
TYPE string.

CHECK lr_queryresult IS BOUND.

CALL METHOD lr_queryresult->get_first
 
RECEIVING
    rv_result = lr_category.

CHECK lr_category IS BOUND.

CALL METHOD lr_category->if_bol_bo_property_access~get_property_as_value
 
EXPORTING
    iv_attr_name =
‘CATEGORY_ID’
 
IMPORTING
    ev_result    = lv_category.

   

Note: Method SET_QUERY_PARAMETERS is used to set the query parameters like Max Hits, Match Type etc.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply