on 08-07-2008 9:52 PM
Hi,
1. Please any one you provide some sample code how can i retrieve
matching result ( records, score, level ) using MDM ABAP API.
2. Using MDM ABAP API is it possible auto merge depend on score or level.
Thanks,
Anil
Hi Anil,
Please go through the link to get useful info about MDM ABAP API's :
How to Identify Identical Master Data Records Using SAP MDM 5.5 ABAP API (NW7.0)-
ABAP API for SAP NetWeaver Master Data Management - Webinar Powerpoint-
How to Identify Identical Master Data Records Using SAP Master Data Management 5.5 ABAP APIs (NW2004)
Some source code is also given in these links. Kindly go through.
Hope it helps.
Thanks and Regards
Nitin jain
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Get the complete code for Matching and Marging everthing automatically mean create transformation, Rule, Strategy then check for merging of Duplicate Records.
&----
*& Report Z_HOW_TO_19
*& Matching
&----
*&
*& How To Tutorial 19:
*& - Instantiates an API object for a particular logical repository
*& - Connects to repository
*& - Creates transformations, rules, strategies
*& - Retrieves transformations, rules, strategies
*& - Invokes matching
*& - Retrieves matching
&----
REPORT z_how_to_19.
DATA lr_api TYPE REF TO cl_mdm_generic_api.
DATA lv_log_object_name TYPE mdm_log_object_name.
DATA ls_language TYPE mdm_cdt_language_code.
DATA cx_exception TYPE REF TO cx_mdm_main_exception.
DATA lr_log TYPE REF TO cl_mdmt_msg_listener.
*create records
DATA ls_parameter TYPE mdm_parameter.
DATA ls_namevalue TYPE mdm_name_value_pair.
DATA lv_data TYPE REF TO data.
DATA lv_string TYPE string.
DATA lv_value TYPE i.
DATA lv_new_id TYPE i.
*transformation structures & tables
DATA lt_match_trans TYPE mdm_match_transformation_table.
DATA ls_match_trans LIKE LINE OF lt_match_trans.
DATA lt_trans_subst TYPE mdm_trans_substitution_table.
DATA ls_trans_subst LIKE LINE OF lt_trans_subst.
*rules structures & tables
DATA lt_match_rule TYPE mdm_matching_rule_table.
DATA ls_match_rule LIKE LINE OF lt_match_rule.
DATA lt_rule_element TYPE mdm_rule_element_table.
DATA ls_rule_element LIKE LINE OF lt_rule_element.
*strategies structures & tables
DATA lt_matching_strategy TYPE mdm_matching_strategy_table.
DATA ls_matching_strategy LIKE LINE OF lt_matching_strategy.
DATA lt_include_rules TYPE mdm_keys.
DATA lv_include_rule LIKE LINE OF lt_include_rules.
*invoke variables
DATA lv_matching_task_id TYPE mdm_gdt_integervalue.
DATA lv_matched_record_count TYPE mdm_gdt_integervalue.
*retrieve match results structures & tables
DATA lt_match_results TYPE mdm_matching_result_table.
DATA ls_match_results LIKE LINE OF lt_match_results.
*query
DATA lt_search_result_set TYPE mdm_search_result_table.
DATA ls_search_result_set TYPE mdm_search_result.
*invoke matching value check structures & tables
DATA ls_match_value_filter TYPE mdm_matching_value_filter.
DATA ls_match_target_filter TYPE mdm_matching_target_filter.
DATA lt_query TYPE mdm_query_table.
DATA ls_query TYPE mdm_query.
DATA lt_result_set TYPE mdm_result_set_table.
DATA ls_result_set LIKE LINE OF lt_result_set.
DATA lv_search_text TYPE string.
*merging variables
DATA ls_record_element TYPE mdm_name_value_pair.
DATA ls_matched_record TYPE mdm_matched_record.
DATA ls_match_results_merge LIKE LINE OF lt_match_results.
DATA lt_internal_ids TYPE mdm_keys.
DATA lv_new_internal_id TYPE i.
DATA lv_id TYPE i.
TYPE-POOLS: mdmif.
*Logical connection name for all operations (to be maintained in customizing)
lv_log_object_name = 'API_CORE_SERVICE_HOWTO'.
*Define logon language, country & region for server
ls_language-language = 'eng'.
ls_language-country = 'US'.
ls_language-region = 'USA'.
Create trace listener
CALL METHOD cl_mdet_listener_factory=>get_instance
EXPORTING
iv_listener_name = 'Lazzy'
RECEIVING
rr_listener_instance = lr_log.
attach the listener
CALL METHOD cl_mdmt_listener_container=>if_mdmt_listener_container~attach
EXPORTING
ir_listener = lr_log.
TRY.
********************************************************************************
CREATE API instance for particular logical repository
Constructor: set logical repository ID of configuration
********************************************************************************
CREATE OBJECT lr_api
EXPORTING
iv_log_object_name = lv_log_object_name.
********************************************************************************
********************************************************************************
********************************************************************************
CONNECT to repository. Apply particular logon language info
********************************************************************************
lr_api->mo_accessor->connect( ls_language ).
********************************************************************************
********************************************************************************
********************************************************************************
*
CREATE records
********************************************************************************
*
*record 1 (artikel 1)
lv_string = 'Artikel1'.
GET REFERENCE OF lv_string INTO lv_data.
ls_namevalue-value = lv_data.
ls_namevalue-code = 'Name'.
APPEND ls_namevalue TO ls_parameter-name_value_pairs.
lv_value = 1000.
GET REFERENCE OF lv_value INTO lv_data.
ls_namevalue-value = lv_data.
ls_namevalue-code = 'Value'.
APPEND ls_namevalue TO ls_parameter-name_value_pairs.
CALL METHOD lr_api->mo_core_service->create
EXPORTING
iv_object_type_code = 'Products'
is_parameter = ls_parameter
IMPORTING
ev_new_internal_id = lv_new_id.
IF lv_new_id NE 0.
WRITE: / 'Successfully created record'.
ENDIF.
FREE ls_parameter-name_value_pairs.
CLEAR ls_parameter.
*record 2 (item 1)
lv_string = 'Item1'.
GET REFERENCE OF lv_string INTO lv_data.
ls_namevalue-value = lv_data.
ls_namevalue-code = 'Name'.
APPEND ls_namevalue TO ls_parameter-name_value_pairs.
lv_value = 10000.
GET REFERENCE OF lv_value INTO lv_data.
ls_namevalue-value = lv_data.
ls_namevalue-code = 'Value'.
APPEND ls_namevalue TO ls_parameter-name_value_pairs.
CALL METHOD lr_api->mo_core_service->create
EXPORTING
iv_object_type_code = 'Products'
is_parameter = ls_parameter
IMPORTING
ev_new_internal_id = lv_new_id.
IF lv_new_id NE 0.
WRITE: / 'Successfully created record'.
ENDIF.
FREE ls_parameter-name_value_pairs.
CLEAR ls_parameter.
*record 3 (item 2)
lv_string = 'ValueCheck'.
GET REFERENCE OF lv_string INTO lv_data.
ls_namevalue-value = lv_data.
ls_namevalue-code = 'Name'.
APPEND ls_namevalue TO ls_parameter-name_value_pairs.
lv_value = 20000.
GET REFERENCE OF lv_value INTO lv_data.
ls_namevalue-value = lv_data.
ls_namevalue-code = 'Value'.
APPEND ls_namevalue TO ls_parameter-name_value_pairs.
CALL METHOD lr_api->mo_core_service->create
EXPORTING
iv_object_type_code = 'Products'
is_parameter = ls_parameter
IMPORTING
ev_new_internal_id = lv_new_id.
IF lv_new_id NE 0.
WRITE: / 'Successfully created record'.
WRITE: /
'__________________________________________________________________________'.
ENDIF.
FREE ls_parameter-name_value_pairs.
CLEAR ls_parameter.
********************************************************************************
*
********************************************************************************
*
********************************************************************************
*
CREATE transformation
********************************************************************************
*
ls_match_trans-transformation_name = 'Trans1'.
ls_match_trans-transformation_code_pair-table_code = 'Products'.
ls_match_trans-transformation_code_pair-field_code = 'Name'.
ls_match_trans-transformation_language_code-language = 'eng'.
ls_match_trans-transformation_language_code-country = ''.
ls_match_trans-transformation_language_code-region = 'USA'.
ls_trans_subst-substitution_from = 'Artikel'.
ls_trans_subst-substitution_to = 'xx'.
APPEND ls_trans_subst TO lt_trans_subst.
ls_trans_subst-substitution_from = 'Item'.
ls_trans_subst-substitution_to = 'xx'.
APPEND ls_trans_subst TO lt_trans_subst.
ls_match_trans-transformation_substitutions = lt_trans_subst.
APPEND ls_match_trans TO lt_match_trans.
CALL METHOD lr_api->mo_core_service->create_match_transformations
EXPORTING
it_transformation_infos = lt_match_trans.
********************************************************************************
*
********************************************************************************
*
********************************************************************************
RETRIEVE transformation
********************************************************************************
FREE lt_match_rule.
CALL METHOD lr_api->mo_core_service->retrieve_match_transformations
IMPORTING
et_transformations = lt_match_trans.
WRITE: / 'Successfully created matching transformation:'.
********************************************************************************
*
********************************************************************************
*
********************************************************************************
RETRIEVE transformation
********************************************************************************
FREE lt_match_rule.
CLEAR ls_match_trans.
CALL METHOD lr_api->mo_core_service->retrieve_match_transformations
IMPORTING
et_transformations = lt_match_trans.
READ TABLE lt_match_trans INTO ls_match_trans INDEX 1.
WRITE: / 'Transformation ID: ', ls_match_trans-transformation_id.
WRITE: / 'Transformation name: ', ls_match_trans-transformation_name.
WRITE: /
'__________________________________________________________________________'.
********************************************************************************
********************************************************************************
********************************************************************************
CREATE rules
********************************************************************************
READ TABLE lt_match_trans INTO ls_match_trans INDEX 1.
ls_rule_element-element_transformation-element_transformation_id =
ls_match_trans-transformation_id.
APPEND ls_rule_element TO lt_rule_element.
ls_match_rule-rule_name = 'Rule1'.
ls_match_rule-rule_elements = lt_rule_element.
ls_match_rule-rule_operator = 'EQ'.
ls_match_rule-rule_succeed_score = 100.
ls_match_rule-rule_default_score = 0.
ls_match_rule-rule_failure_score = 1.
APPEND ls_match_rule TO lt_match_rule.
CLEAR ls_rule_element.
FREE lt_rule_element.
ls_rule_element-element_field-element_code_pair-table_code = 'Products'.
ls_rule_element-element_field-element_code_pair-field_code = 'Name'.
APPEND ls_rule_element TO lt_rule_element.
ls_match_rule-rule_name = 'Rule2'.
ls_match_rule-rule_elements = lt_rule_element.
ls_match_rule-rule_operator = 'EQ'.
ls_match_rule-rule_succeed_score = 100.
ls_match_rule-rule_default_score = 0.
ls_match_rule-rule_failure_score = 1.
APPEND ls_match_rule TO lt_match_rule.
CALL METHOD lr_api->mo_core_service->create_match_rules
EXPORTING
it_rules = lt_match_rule.
********************************************************************************
********************************************************************************
********************************************************************************
RETRIEVE rules
********************************************************************************
FREE lt_match_rule.
CALL METHOD lr_api->mo_core_service->retrieve_match_rules
IMPORTING
et_rules = lt_match_rule.
LOOP AT lt_match_rule INTO ls_match_rule.
WRITE: / 'Rule ID: ', ls_match_rule-rule_id.
WRITE: / 'Rule name: ', ls_match_rule-rule_name.
ENDLOOP.
WRITE: /
'__________________________________________________________________________'.
********************************************************************************
********************************************************************************
********************************************************************************
*
CREATE strategy
********************************************************************************
*
LOOP AT lt_match_rule INTO ls_match_rule.
lv_include_rule = ls_match_rule-rule_id.
APPEND lv_include_rule TO lt_include_rules.
ENDLOOP.
ls_matching_strategy-strategy_name = 'Strateg1'.
ls_matching_strategy-strategy_lower_threshold = 30.
ls_matching_strategy-strategy_upper_threshold = 45.
ls_matching_strategy-strategy_included_rules = lt_include_rule
APPEND ls_matching_strategy TO lt_matching_strategy.
CALL METHOD lr_api->mo_core_service->create_match_strategies
EXPORTING
it_strategies = lt_matching_strategy.
WRITE: / 'Successfully created matching strategy:'.
********************************************************************************
*
********************************************************************************
*
********************************************************************************
RETRIEVE strategy
********************************************************************************
FREE lt_matching_strategy.
CALL METHOD lr_api->mo_core_service->retrieve_match_strategies
IMPORTING
et_strategies = lt_matching_strategy.
READ TABLE lt_matching_strategy INTO ls_matching_strategy INDEX 1.
WRITE: / 'Strategy ID: ', ls_matching_strategy-strategy_id.
WRITE: / 'Strategy name: ', ls_matching_strategy-strategy_name.
WRITE: /
'__________________________________________________________________________'.
********************************************************************************
********************************************************************************
********************************************************************************
INVOKE matching
********************************************************************************
READ TABLE lt_matching_strategy INTO ls_matching_strategy INDEX 1.
CALL METHOD lr_api->mo_core_service->invoke_matching
EXPORTING
iv_object_type_code = 'Products'
iv_strategy_id = ls_matching_strategy-strategy_id
is_matching_filter =
iv_wait_for_invocation = 'X'
IMPORTING
ev_matching_task_id = lv_matching_task_id
ev_matched_record_count = lv_matched_record_count.
WRITE: / 'Successfully invoked matching.'.
WRITE: /
'__________________________________________________________________________'.
********************************************************************************
********************************************************************************
********************************************************************************
Retrieve matching results
********************************************************************************
CALL METHOD lr_api->mo_core_service->query
EXPORTING
iv_object_type_code = 'Products'
IMPORTING
et_result_set = lt_search_result_set.
READ TABLE lt_search_result_set INTO ls_search_result_set INDEX 1.
CALL METHOD lr_api->mo_core_service->retrieve_matching_result
EXPORTING
iv_matching_task_id = lv_matching_task_id
it_record_ids = ls_search_result_set-record_ids
iv_object_type_code =
it_query_records =
iv_include_matched_records = abap_true
iv_start_with =
iv_hits_max =
is_sort_information =
is_result_set_definition =
IMPORTING
et_matching_result = lt_match_results.
DATA lv_found TYPE i.
lv_found = 0.
WRITE: / 'Successfully retrieved matching results:'.
LOOP AT lt_match_results INTO ls_match_results.
WRITE: / 'Record ID: ', ls_match_results-checked_record_id.
WRITE: / 'Matching score: ', ls_match_results-matching_score.
WRITE: / 'Number of matches: ', ls_match_results-number_of_matches.
WRITE: / '****'.
IF ls_match_results-matching_score GE 100 AND
lv_found = 0.
ls_match_results_merge = ls_match_results.
lv_found = 1.
ENDIF.
ENDLOOP.
WRITE: /
'__________________________________________________________________________'.
********************************************************************************
********************************************************************************
*break-point to check the results in data manager (before merge)
BREAK-POINT.
********************************************************************************
Merge two matching records
********************************************************************************
*retrieve records to merge (2)
APPEND ls_match_results_merge-checked_record_id TO lt_internal_ids.
LOOP AT ls_match_results_merge-matched_records INTO ls_matched_record.
IF ls_matched_record-matching_score GE 100.
APPEND ls_matched_record-record_id TO lt_internal_ids.
ENDIF.
ENDLOOP.
CALL METHOD lr_api->mo_core_service->retrieve
EXPORTING
iv_object_type_code = 'Products'
it_keys = lt_internal_ids
IMPORTING
et_result_set = lt_result_set.
LOOP AT lt_result_set INTO ls_result_set.
IF sy-tabix EQ 1.
READ TABLE ls_result_set-name_value_pairs INTO ls_record_element INDEX
1.
APPEND ls_record_element TO ls_parameter-name_value_pairs.
ELSEIF sy-tabix EQ 2.
READ TABLE ls_result_set-name_value_pairs INTO ls_record_element INDEX
3.
APPEND ls_record_element TO ls_parameter-name_value_pairs.
ENDIF.
ENDLOOP.
CALL METHOD lr_api->mo_core_service->merge
EXPORTING
iv_object_type_code = 'Products'
it_internal_ids = lt_internal_ids
is_parameter = ls_parameter
IMPORTING
ev_new_internal_id = lv_new_internal_id.
IF lv_new_internal_id NE 0.
WRITE: / 'Successfully merged.'.
ELSE.
WRITE: / 'Mergin caused an error.'.
ENDIF.
WRITE: /
'__________________________________________________________________________'.
********************************************************************************
********************************************************************************
********************************************************************************
INVOKE matching value check
********************************************************************************
*Query for record id:
Fill query structure with parameters
ls_query-parameter_code = 'Name'. "Field code
ls_query-operator = 'EQ'. "Equals
ls_query-dimension_type = mdmif_search_dim_field. "Field search
dimension
ls_query-constraint_type = mdmif_search_constr_text. "Text search
constraint
Assign search text to value low
lv_search_text = 'ValueCheck'.
GET REFERENCE OF lv_search_text INTO ls_query-value_low.
APPEND ls_query TO lt_query.
Query on records (search for value 'Artikel1' in field category of table
Products)
FREE lt_search_result_set.
CALL METHOD lr_api->mo_core_service->query
EXPORTING
iv_object_type_code = 'Products'
it_query = lt_query
IMPORTING
et_result_set = lt_search_result_set.
READ TABLE lt_search_result_set INTO ls_search_result_set INDEX 1.
CALL METHOD lr_api->mo_core_service->retrieve
EXPORTING
iv_object_type_code = 'Products'
it_result_set_definition =
it_keys = ls_search_result_set-record_ids
IMPORTING
et_result_set = lt_result_set.
READ TABLE lt_result_set INTO ls_match_value_filter-value_filter INDEX 1.
CALL METHOD lr_api->mo_core_service->invoke_matching_value_check
EXPORTING
iv_object_type_code = 'Products'
iv_strategy_id = ls_matching_strategy-strategy_id
is_matching_value_filter = ls_match_value_filter
iv_wait_for_invocation = 'X'
IMPORTING
ev_matching_task_id = lv_matching_task_id
ev_matched_record_count = lv_matched_record_count.
WRITE: / 'Successfully invoked matching (value check).'.
WRITE: /
'__________________________________________________________________________'.
*******************************************************************************
********************************************************************************
********************************************************************************
Retrieve matching results
********************************************************************************
FREE lt_search_result_set.
CALL METHOD lr_api->mo_core_service->query
EXPORTING
iv_object_type_code = 'Products'
IMPORTING
et_result_set = lt_search_result_set.
READ TABLE lt_search_result_set INTO ls_search_result_set INDEX 1.
CALL METHOD lr_api->mo_core_service->retrieve_matching_result
EXPORTING
iv_matching_task_id = lv_matching_task_id
it_record_ids = ls_search_result_set-record_ids
iv_object_type_code =
it_query_records =
iv_include_matched_records = abap_true
iv_start_with =
iv_hits_max =
is_sort_information =
is_result_set_definition =
IMPORTING
et_matching_result = lt_match_results.
WRITE: / 'Successfully retrieved matching results:'.
LOOP AT lt_match_results INTO ls_match_results.
WRITE: / 'Record ID: ', ls_match_results-checked_record_id.
WRITE: / 'Matching score: ', ls_match_results-matching_score.
WRITE: / 'Number of matches: ', ls_match_results-number_of_matches.
WRITE: / '****'.
ENDLOOP.
WRITE: /
'__________________________________________________________________________'.
********************************************************************************
********************************************************************************
*break-point to check the results in data manager (after merge)
BREAK-POINT.
********************************************************************************
Delete records
********************************************************************************
CALL METHOD lr_api->mo_core_service->query
EXPORTING
iv_object_type_code = 'Products'
IMPORTING
et_result_set = lt_search_result_set.
READ TABLE lt_search_result_set INTO ls_search_result_set INDEX 1.
CALL METHOD lr_api->mo_core_service->delete
EXPORTING
iv_object_type_code = 'Products'
it_internal_ids = ls_search_result_set-record_ids.
WRITE: / 'Successfully deleted records'.
WRITE: /
'__________________________________________________________________________'.
********************************************************************************
*******************************************************************************
********************************************************************************
Disconnect after exception has occurred.
This prevents server resource from becoming exhausted
********************************************************************************
lr_api->mo_accessor->disconnect( ).
CATCH cx_mdm_usage_error INTO cx_exception. "#EC NO_HANDLER
handle exception
CATCH cx_mdm_provider INTO cx_exception. "#EC NO_HANDLER
handle exception
CATCH cx_mdm_kernel INTO cx_exception. "#EC NO_HANDLER
handle exception
CATCH cx_mdm_server_rc_code INTO cx_exception. "#EC NO_HANDLER
handle exception
CATCH cx_mdm_not_supported INTO cx_exception. "#EC NO_HANDLER
handle exception
CLEANUP.
Disconnect after finishing work. This prevents server resource from becoming
exhausted
TRY.
********************************************************************************
lr_api->mo_accessor->disconnect( ).
********************************************************************************
Ignore all exceptions here:
CATCH cx_root. "#EC NO_HANDLER
ENDTRY.
ENDTRY.
IF NOT cx_exception IS INITIAL.
NEW-LINE.
WRITE 'Error occured. Program terminated'.
NEW-LINE.
DATA lv_text TYPE string.
lv_text = cx_exception->if_message~get_text( ).
WRITE lv_text.
ENDIF.
Hope it will Help you,
Thanks,
Mandeep Saini
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anil,
Using the following commands you can retrieve the matching result.
ExecuteMatchingStrategyCommand
A command to execute a matching strategy for internal source records.
ExecutetMatchingStrategyForNewRecordValuesCommand
A command to execute a matching strategy for external source records.
RetrieveMatchedRecordsCommand
A command to retrieve the records that matched the source record for a matching strategy.
RetrieveMatchingResultCommand
A command to retrieve the matching results for a matching strategy.
RetrieveMatchingStrategiesCommand
A command to retrieve the list of matching strategies.
TerminateMatchingStrategyCommand
A command to terminate a running matching strategy.
Use RetrieveMatchingStrategiesCommand to get the stretagies available in MDM
RetrieveMatchedRecordsCommand get the records that match the stretagies.
and then loop through all to work.
You can also follow the below blog which will guide you on the similar operations:
Additionally follow these related links as well
Hope It Helped,
Thanks & Regards
Simona Pinto
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.