SAP MDG · WORKFLOWS

How do I implement MDG material key mapping on activation with the ID matching API?

Implement the material key-mapping system method on activation by reading all materials in the Change Request, determining the local business system, creating an ID matching API instance, building search keys, and adding source-to-target mappings for records that carry source system and source material values.

Implement the material key-mapping system method on activation by reading all materials in the Change Request, determining the local business system, creating an ID matching API instance, building search keys, and adding source-to-target mappings for records that carry source system and source material values.

`ZCL_BADI_MM_KEY_MAPPING` is the activation-time material key-mapping system method. It reads the CR materials, derives the local business system, creates the ID matching API instance, builds a search key for each material, and then adds the current source-to-target mapping for records that contain source-system and source-material values.

Process flow

  1. Read all materials in the Change Request with `read_material`.
  2. Determine the local business system using `LCR_GET_OWN_BUSINESS_SYSTEM`.
  3. Create the ID matching API instance with `CL_MDG_ID_MATCHING_API_BS=>GET_INSTANCE`.
  4. Build `MDG_S_OBJECT_KEY_BS` entries for each material using the local business system, material ID, object type code `194`, and scheme `IF_MDG_IDSC_CONST=>MATERIAL_ID_EXT` (`'924'`).
  5. Optionally remove stale mappings using the existing mapping deletion logic in the productive class.
  6. For each material with source fields, create source and target identifiers using `IF_MDG_IDSC_CONST=>MATERIAL_ID` (`'20'`).
  7. Call `ADD_MATCHING` with `MDG_T_ADD_MATCHING_EASY_BS` and then `SAVE`.
  8. Perform `COMMIT WORK AND WAIT` and `CLEANUP_BUFFER( iv_force_cleanup = abap_true )`.

Referenced tables

ObjectPurpose
MDG_S_OBJECT_KEY_BSSearch key structure for the local business-system/material identifier used when looking up or aligning mappings.
MDG_S_ADD_MATCHING_EASY_BSSingle matching payload structure passed to `ADD_MATCHING` for source-to-target key mapping.
MDG_T_OBJECT_KEY_BSInternal table of search keys built for the Change Request materials.
MDG_T_ADD_MATCHING_EASY_BSInternal table of match records accumulated before save.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example: utilize_BAdI_rule_based_workflow_create_followup_change_request.abap

Exact relevant implementation excerpt from the knowledge document set.

1"! <p class="shorttext"><strong>SAP MDG Rule-Based Workflow</strong><br/> 2"! Call a synchronous system method to create a follow-up Change Request</p> 3"! 4"! <p>Source-document code reference for BAdI 5"! {@link USMD_SSW_SYSTEM_METHOD_CALLER} and method 6"! {@link IF_USMD_SSW_SYST_METHOD_CALLER~CALL_SYSTEM_METHOD}.</p> 7"! 8"! <h2>SAP objects</h2> 9"! <ul> 10"! <li>Enhancement spot: USMD_SSW_SERVICE_PROCESSOR</li> 11"! <li>BAdI: USMD_SSW_SYSTEM_METHOD_CALLER</li> 12"! <li>Interface: IF_USMD_SSW_SYST_METHOD_CALLER</li> 13"! <li>Method: IF_USMD_SSW_SYST_METHOD_CALLER~CALL_SYSTEM_METHOD</li> 14"! <li>Sample enhancement implementation: MDG_BS_MAT_CREATE_SUCCESSOR_CR</li> 15"! <li>Required SAP Note: 3199378</li> 16"! <li>Service name used by the scenario: ZCREATE_FOLLOW_UP_CR</li> 17"! <li>Process pattern: 02 - Synchronous System Method</li> 18"! </ul> 19"! 20"! <h2>Important source limitation</h2> 21"! <p>The PDF contains a screenshot of only the beginning of the copied SAP 22"! sample method. It does not print the complete sample-class source. The 23"! excerpt below therefore ends exactly where the visible screenshot ends. 24"! No missing continuation has been invented.</p> 25"! 26"! @tags SAP-MDG Rule-Based-Workflow Follow-Up-Change-Request 27"! @tags USMD_SSW_SYSTEM_METHOD_CALLER USMD_SSW_SERVICE_PROCESSOR 28"! @tags CALL_SYSTEM_METHOD ZCREATE_FOLLOW_UP_CR Process-Pattern-02 29 30*---------------------------------------------------------------------* 31* Generic and scenario-specific object names shown in the guide 32*---------------------------------------------------------------------* 33* Generic enhancement implementation : ZMY_SERVICE_CALL_SYSTEM_METHOD 34* Scenario enhancement implementation: ZBDI_CREATE_FOLLOW_UP_CR 35* 36* Generic BAdI implementation : ZMY_SERVICE_CALL_SYSTEM_METHOD 37* Scenario BAdI implementation : ZBDI_CREATE_FOLLOW_UP_CR 38* 39* Generic implementing class : ZCL_MY_SERVICE_CALL_SYS_METHOD 40* Scenario implementing class : ZCL_ZBDI_CREATE_FOLLOW_UP_CR 41* 42* Generic filter value : ZMY_SERVICE_NAME 43* Scenario filter value : ZCREATE_FOLLOW_UP_CR 44* 45* Filter : SERVICE_NAME 46* Comparator : = 47*---------------------------------------------------------------------* 48 49*---------------------------------------------------------------------* 50* Visible method parameters in the PDF 51*---------------------------------------------------------------------* 52* IV_CR_NUMBER TYPE USMD_CREQUEST 53* IV_SERVICE_NAME 54* EV_ACTION 55* ET_MESSAGE 56* CT_CONTEXT_TAB 57* CX_BO_TEMPORARY 58*---------------------------------------------------------------------* 59 60*---------------------------------------------------------------------* 61* Code excerpt visible in the PDF screenshot 62*---------------------------------------------------------------------* 63 64METHOD if_usmd_ssw_syst_method_caller~call_system_method. 65 "* Create a follow-up change request with reference to an existing, closed change request 66 67 "Use the fieldnames and types of database table USD120C for defining the local type 68 TYPES: BEGIN OF lty_crequest, 69 usmd_crequest TYPE usmd_crequest, 70 usmd_created_by TYPE xubname, 71 END OF lty_crequest. 72 DATA lt_crequest TYPE SORTED TABLE OF lty_crequest WITH UNIQUE KEY usmd_crequest. 73 74 "Clear the exporting parameter 75 CLEAR: ev_action, et_message. 76 77 CASE iv_service_name. 78 WHEN 'insert your service name (as defined via IMG) here'. 79 80 "Ensure that the reference change request number is provided 81 IF iv_cr_number IS INITIAL. 82 "Implement proper error handling here... 83 RETURN. 84 ENDIF. 85 86 "Get an instance of the External Model API 87 cl_usmd_model_ext=>get_instance( 88 EXPORTING 89 i_usmd_model = space "No data model need to be provided here 90 IMPORTING 91 eo_instance = DATA(lo_model_ext) 92 et_message = et_message ). 93 IF et_message IS NOT INITIAL. 94 "Do proper error handling 95 RETURN. 96 ENDIF. 97 98*---------------------------------------------------------------------* 99* End of source excerpt visible in the PDF. 100* The remaining CASE logic and method ending are not shown. 101*---------------------------------------------------------------------*

The remaining configuration, implementation details, and testing guidance continue from this answer more…

Related questions and keywords

Alternative questions

  • How does the MDG material key mapping system method work?
  • How do I create or update cross-system material key mapping during activation?
  • What is the ABAP pattern for `ZCL_BADI_MM_KEY_MAPPING`?

Possible questions

  • What does the material key mapping system method do during activation?
  • Which API is used to add material key mappings in MDG?
  • How do I read materials from the Change Request before key mapping?
  • How do I build source and target identifiers for MDG key mapping?
  • What is the object type code for material key mapping in the sample?

Keywords

ZCL_BADI_MM_KEY_MAPPINGIF_USMD_SSW_SYST_METHOD_CALLERIF_MDG_ID_MATCHING_API_BSCL_MDG_ID_MATCHING_API_BS=>GET_INSTANCELCR_GET_OWN_BUSINESS_SYSTEMIF_MDG_IDSC_CONST=>MATERIAL_ID_EXTIF_MDG_IDSC_CONST=>MATERIAL_IDMDG_S_OBJECT_KEY_BSMDG_S_ADD_MATCHING_EASY_BSZMDG_MM_KEY_MAPPING_SMC