SAP MDG · REPLICATION INBOUND
How do I implement mass key mapping upload in SAP MDG using a custom ABAP report and the MDG ID matching API?
Use a custom upload report to read the file, split each row into source and target object data, validate the IDs through the MDG ID matching BAdI/API, check for existing mappings, then call add_matching and save only when validation passes.
Use a custom upload report to read the file, split each row into source and target object data, validate the IDs through the MDG ID matching BAdI/API, check for existing mappings, then call add_matching and save only when validation passes.
The upload part of `ZCREATE_MASS_KEY_MAPPNG` reads the input file, maps each CSV row into source and target object identifiers, validates the IDs through the MDG ID matching BAdI/API, checks whether the mapping already exists, and saves only clean records. It also writes application-log messages for invalid source/target IDs, invalid system IDs, and duplicate mappings.
Process flow
- Read the input file into `et_filecontent` with the upload helper.
- Skip the first row as the header and split each row into eight fields.
- Resolve object type and ID type text to technical codes using `MDGI_OTC_T_BS` and `MDGI_IDSTC_T_BS`.
- Populate source and target identifier structures for `mdg_s_add_matching_easy_bs`.
- Call the BAdI method `upload_field_validation` for row-level validation.
- Call `get_matching` to detect existing mappings for the same source key.
- Compare the returned target identifiers to detect duplicates.
- If validation passes, call `add_matching` and then `save`.
Referenced tables
| Object | Purpose |
|---|---|
MDGI_IDSTC_T_BS | Used to resolve ID object type descriptions to `ids_type_code`. |
MDGI_OTC_T_BS | Used to resolve object type descriptions to `object_type_code`. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1*----------------------------------------------------------------------*
2***INCLUDE CREATE_MASS_KEY_MAPPING_UPLOAD .
3*----------------------------------------------------------------------*
4*&---------------------------------------------------------------------*
5*& Form UPLOAD_DATA
6*&---------------------------------------------------------------------*
7* text
8*----------------------------------------------------------------------*
9* -->P_P_PATH text
10*----------------------------------------------------------------------*
11FORM upload_data USING p_p_path p_p_lines " Note 2514101
12 obj_type.
13
14 TYPES: BEGIN OF ls_message_str,
15 msgty TYPE symsgty,
16 msgid TYPE symsgid,
17 msgno TYPE symsgno,
18 msgv1 TYPE symsgv,
19 msgv2 TYPE symsgv,
20 msgv3 TYPE symsgv,
21 msgv4 TYPE symsgv,
22 msg_index TYPE /plmb/spi_msg_index,
23 fieldname TYPE fieldname,
24 END OF ls_message_str.
25* TYPES : lt_message_str TYPE TABLE OF ls_message_str.
26
27 DATA: et_filecontent TYPE TABLE OF string,
28 es_filecontent TYPE string.
29 DATA lv_save_successful TYPE boole_d.
30 DATA: lr_input_val TYPE REF TO bs_gis_key_mapping.
31 DATA: n TYPE i.
32 DATA: ls_search_key TYPE mdg_s_object_key_bs.
33 DATA: et_messages TYPE TABLE OF ls_message_str,
34 lt_messages TYPE TABLE OF ls_message_str,
35 ls_message TYPE ls_message_str,
36 lv_no_matching_object_found TYPE boole_d ,
37 lv_object_not_found TYPE boole_d ,
38 ls_objects TYPE mdg_s_get_object_data_bs,
39 lv_msg_severity TYPE /plmb/spi_msg_severity,
40 lv_msgid TYPE symsgid,
41 lv_msgty TYPE symsgty,
42 lv_msgno TYPE symsgno,
43 lv_msgv1 TYPE symsgv,
44 lv_msgv2 TYPE symsgv,
45 lv_msgv3 TYPE symsgv,
46 lv_msgv4 TYPE symsgv,
47 lt_index_failed TYPE /plmb/t_spi_index_failed.
48 DATA: str1 TYPE string,
49 str2 TYPE string,
50 str3 TYPE string,
51 str4 TYPE string,
52 str5 TYPE string,
53 str6 TYPE string,
54 str7 TYPE string,
55 str8 TYPE string.
56 DATA: lv_source_sys_id TYPE sld_bskey,
57 lv_source_obj_id TYPE mdg_object_id_bs,
58 lv_target_sys_id TYPE sld_bskey,
59 lv_target_obj_id TYPE mdg_object_id_bs.
60 DATA: lv_error TYPE c,
61 lv_error_save TYPE c.
62 DATA lv_index TYPE sy-index.
63 DATA: oitc TYPE mdg_ids_type_code_bs,
64 sys_id TYPE sld_bskey,
65 id_value TYPE mdg_object_id_bs,
66 object_type_code TYPE mdg_object_type_code_bs,
67 ext_oitc TYPE mdg_ids_type_code_bs,
68 ext_sys_id TYPE sld_bskey,
69 ext_id_value TYPE mdg_object_id_bs,
70 ls_mdg_s_get_matching_easy_bs TYPE mdg_s_get_matching_easy_bs,
71 ext_object_type_code TYPE mdg_object_type_code_bs.
72
73 DATA: lv_obj_type_code TYPE mdg_object_type_code_bs,
74 lv_int_bus_sys_id TYPE sld_bskey,
75 ls_mapped_object TYPE mdg_s_matching_obj_data_bs,
76 ls_obj_identifier TYPE mdg_s_identifier_data_bs,
77 lr_if_mdg_id_matching_api TYPE REF TO if_mdg_id_matching_api_bs.
78
79 DATA lt_mapping_data TYPE mdg_t_add_matching_easy_bs.
80 DATA ls_mapping_data TYPE mdg_s_add_matching_easy_bs.
81 DATA: lt_identifier TYPE mdg_t_identifier_bs,
82 ls_identifier TYPE mdg_s_identifier_bs.
83 DATA: ls_object_id_types LIKE LINE OF gt_object_id_types,
84 ls_object_types LIKE LINE OF gt_object_types.
85
86*******read the excel values into table
87
88 PERFORM upload_execl TABLES et_filecontent
89 USING p_p_path p_p_lines. " Note 2514101
90 SELECT * FROM mdgi_idstc_t_bs INTO TABLE gt_object_id_types WHERE langu = sy-langu.
91 SELECT * FROM mdgi_otc_t_bs INTO TABLE gt_object_types WHERE langu = sy-langu.
92
93 SORT gt_object_id_types BY description.
94 SORT gt_object_types BY description.
95
96 DATA: lt_data TYPE TABLE OF string,
97 ls_data TYPE string.
98
99 GET BADI lr_input_val
100 FILTERS
101 gis_object_type = obj_type.
102
103* Instantiate the API for mapping
104 CALL METHOD cl_mdg_id_matching_api_bs=>get_instance
105 EXPORTING
106 iv_direct_db_insert = abap_false
107 iv_set_lcl_system_by_api = abap_true
108 IMPORTING
109 er_if_mdg_id_matching_api = lr_if_mdg_id_matching_api.
110
111******start looping the values from excel*********************
112 LOOP AT et_filecontent INTO es_filecontent.
113
114 SPLIT es_filecontent AT ',' INTO : str1 str2 str3 str4 str5 str6 str7 str8.
115 n = n + 1.
116 IF n EQ 1.
117 CONTINUE.
118 ENDIF.
119 lv_index = sy-tabix.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How does the custom MDG key mapping upload report validate and save records?
- How do I build a mass upload for MDG key mapping from a file?
- How do I use the MDG ID matching BAdI/API for inbound key mapping creation?
Possible questions
- How do I implement mass key mapping upload in SAP MDG using a custom ABAP report and the MDG ID matching API?
- How does the custom MDG key mapping upload report validate and save records?
- How do I build a mass upload for MDG key mapping from a file?
- How do I use the MDG ID matching BAdI/API for inbound key mapping creation?
- How do I troubleshoot duplicate or invalid key mapping records in upload mode?