cancel
Showing results for 
Search instead for 
Did you mean: 

MDM ABAP API: Query with Multiple Parameters

Former Member
0 Kudos

I would like to query MDM repository passing multiple parameters. I used the following code, however, it didn't work.

If I pass only one parameter, it works fine.

DATA lt_query                  TYPE mdm_query_table.
DATA ls_query                 TYPE mdm_query.
DATA lv_search_text       TYPE string.
DATA lt_result_set            TYPE mdm_search_result_table.
DATA ls_result_set           LIKE LINE OF lt_result_set.

* Fill query structure with FIRST parameter 
    ls_query-parameter_code  = 'Name'.
    ls_query-operator        = 'CS'.  
    ls_query-dimension_type  = mdmif_search_dim_field.     
    ls_query-constraint_type = mdmif_search_constr_text. 
    lv_search_text = 'BMW'.
    GET REFERENCE OF lv_search_text INTO ls_query-value_low.
    APPEND ls_query TO lt_query.

* Fill query structure with SECOND parameter 
    ls_query-parameter_code  = 'Model'.
    ls_query-operator        = 'CS'.  
    ls_query-dimension_type  = mdmif_search_dim_field.     
    ls_query-constraint_type = mdmif_search_constr_text. 
    lv_search_text = '2009'.
    GET REFERENCE OF lv_search_text INTO ls_query-value_low.
    APPEND ls_query TO lt_query.

* Query on records (search for value 'BMW' model '2009' in table Products)
    CALL METHOD lr_api->mo_core_service->query
      EXPORTING
        iv_object_type_code = 'Products'                   
        it_query            = lt_query
      IMPORTING
        et_result_set       = lt_result_set.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member205403
Active Contributor
0 Kudos

Hi,

I see you are not clearing your local structure "ls_query". This could be reason of problem, try this and let us know the result:

DATA lt_query TYPE mdm_query_table.

DATA ls_query TYPE mdm_query.

DATA lv_search_text TYPE string.

DATA lt_result_set TYPE mdm_search_result_table.

DATA ls_result_set LIKE LINE OF lt_result_set.

  • Fill query structure with FIRST parameter

ls_query-parameter_code = 'Name'.

ls_query-operator = 'CS'.

ls_query-dimension_type = mdmif_search_dim_field.

ls_query-constraint_type = mdmif_search_constr_text.

lv_search_text = 'BMW'.

GET REFERENCE OF lv_search_text INTO ls_query-value_low.

APPEND ls_query TO lt_query.

CLEAR ls_query.

  • Fill query structure with SECOND parameter

ls_query-parameter_code = 'Model'.

ls_query-operator = 'CS'.

ls_query-dimension_type = mdmif_search_dim_field.

ls_query-constraint_type = mdmif_search_constr_text.

lv_search_text = '2009'.

GET REFERENCE OF lv_search_text INTO ls_query-value_low.

APPEND ls_query TO lt_query.

CLEAR ls_query.

  • Query on records (search for value 'BMW' model '2009' in table Products)

CALL METHOD lr_api->mo_core_service->query

EXPORTING

iv_object_type_code = 'Products'

it_query = lt_query

IMPORTING

et_result_set = lt_result_set.

Former Member
0 Kudos

Thanks a lot Shiv,

But clearing the query didn't help.

Former Member
0 Kudos

One of my brilliant colleagues resolve this issue. Code should be like the following:

DATA lt_query                  TYPE mdm_query_table.
DATA lv_search_text       TYPE string.
DATA lt_result_set            TYPE mdm_search_result_table.
DATA ls_result_set           LIKE LINE OF lt_result_set.
 
FIELD-SYMBOLS  <ls_query> TYPE mdm_query.

* Fill query structure with FIRST parameter 
    APPEND INITIAL LINE TO lt_query ASSIGNING <ls_query>.
    <ls_query>-parameter_code  = 'Name'.
    <ls_query>-operator        = 'CS'.  
    <ls_query>-dimension_type  = mdmif_search_dim_field.     
    <ls_query>-constraint_type = mdmif_search_constr_text. 
    lv_search_text = 'BMW'.
    GET REFERENCE OF lv_search_text INTO <ls_query>--value_low.
    UNASSIGN <ls_query>.
 
* Fill query structure with SECOND parameter 
    <ls_query>-parameter_code  = 'Model'.
   <ls_query>-operator        = 'CS'.  
   <ls_query>-dimension_type  = mdmif_search_dim_field.     
    <ls_query>-constraint_type = mdmif_search_constr_text. 
    lv_search_text = '2009'.
    GET REFERENCE OF lv_search_text INTO <ls_query>--value_low.
    UNASSIGN <ls_query>.
 
* Query on records (search for value 'BMW' model '2009' in table Products)
    CALL METHOD lr_api->mo_core_service->query
      EXPORTING
        iv_object_type_code = 'Products'                   
        it_query            = lt_query
      IMPORTING
        et_result_set       = lt_result_set.

Former Member
0 Kudos

Hi Abdulla,

Please use two different Reference Variables for Each field. I.e. lv_search_Name and lv_search_Model.

You are using same Reference for each Field leads to Reference modification for each overwrite everywhere.

Regards,

Sekhar.J