Using MDM Java APIs to retrieve and execute Matching strategies in MDM


SAP MDM Interview Questions and SAP MDM Tutorials

SAP MDM Interview Questions and SAP MDM Tutorials

Using MDM Java APIs to retrieve and execute Matching strategies in MDM

Taking forward, the build  for my Customised Data Manger using MDM Java APIs, please find this blog as the new addition the series:
 Using MDM Java APIs to retrieve Taxonomy attribute Values                                 
 Using MDM Java APIs to add Text(type) taxonomy attribute allowable values
Before I demonstrate using MDM Java APIs to retrieve matching strategies, let us understand what are matching strategies and how do we create or add them in MDM.
A matching strategy is comprised of one or more matching rules and a pair of numeric thresholds.Each strategy can be executed against a set of one or more records against the set, the search results, or all of the records in the repository.
Matching strategies identify potential matches for each record based on the matching scores of the individual rules that comprise the strategy and the thresholds that determine which records are potential matches for each record.
1. As a first step we will create a matching strategy from with in Matching Mode of Data Manager, to add a new strategy to the list of strategies:

SAP MDM Interview Questions and SAP MDM Tutorials

SAP MDM Interview Questions and SAP MDM Tutorials

  • If necessary, click on the Strategies tab to make it the active tab.
  • Right-click in the Strategies pane and choose Add Strategy from the context menu, or choose Records > Matching > Strategies > Add Item from the main menu.
  • MDM adds a new matching strategy named “New Strategy” to the list of strategies, and highlights it for editing.
  • Include the columns against which target records are to matched, say Material_Number in current scenario.
  • Type the name ‘Material Strategy’ for the matching strategy and press Enter.

2. Now since we have created the matching strategy by the name ‘Material Strategy’ let us look at the MDM Java API code snippets, which will be required to execute the matching strategy. Using the Java API, at first we reteieve matching strategies available in MDM repository:

RetrieveMatchingStrategiesCommand retMatStr =  new RetrieveMatchingStrategiesCommand(connection);
retMatStr.setSession(authUserSession);
try {
retMatStr.execute(); }
catch (CommandException e) {
e.printStackTrace(); }
// we have only one matching strategy, retriving the matching strategy id
matchStID = retMatStr.getMatchingStrategies()[1].getId();
….where
connection & authUserSession vaiables hold MDM Connection and authenticated user session respectively
After fetching the matching strategy id, we are left with two following steps:
3. For any new records being created,using the matching strategy id we execute the matching strategy to find mathcing records:

ExecuteMatchingStrategyForNewRecordValuesCommand exeMatstr = new ExecuteMatchingStrategyForNewRecordValuesCommand(connection);
exeMatstr.setSession(authUserSession);
exeMatstr.setStrategyId(matchStID);
exeMatstr.setSource(recs);
exeMatstr.setTarget(rids);
exeMatstr.setTarget(new Search(new TableId(1)));
try
{
exeMatstr.execute();
}
catch (CommandException e)
{
e.printStackTrace();
}
….where
recs is the array of source records, these are records to find matching for, currently only one record is supported
rids is the array of target recod ids, these are the recods to match to
setTarget(new Search(new TableId(1))) sets the target records in form of a search object, these are the records to match to, i.e. all records in main table
4. After executing the matching strategy we execute the RetrievedMatchedRecordsCommand, to retrieve the records that matched the source record for the matching strategy, which was executed:

RetrieveMatchedRecordsCommand retMR = new RetrieveMatchedRecordsCommand(connection);
retMR.setSession(authUserSession);
retMR.setMatchingTaskId(exeMatstr.getMatchingTaskId());
retMR.setRecordId(new RecordId(-1));
retMR.setResultDefinition(new ResultDefinition(new TableId(1)));
try {
retMR.execute(); }
catch (CommandException e) {
e.printStackTrace(); }
…..where
setMatchingTaskId(exeMatstr.getMatchingTaskId()) sets the matching task Id  fetched using executeMatchingStrategy command object from the last step, this identifier is a handle to the matching stratgey that was executed in the last step.
setRecordId(new RecordId(-1)) sets the source record Id, the matched records will be based on this source record.For external record matching, the record Id is -1.

As discussed in the blog, one can use the steps to execute matching strategies already existing in MDM in a different way. Though one might argue for running parallel searches in MDM using the API to accomplish certain kind of matching between records, instead of executing matching strategies this way. I would say this is a feature provided by the java API, it empowers developer to replicate data manager features over the web, and I personally feel using it this way would save a lot of development time required to explicitly code such a matching strategy using the APIs.

 

SAP MDM Interview Questions and SAP MDM Tutorials

SAP MDM Interview Questions and SAP MDM Tutorials

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter
   Send article as PDF   
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *