SAP MDG · REPLICATION INBOUND

How do I implement an SAP MDG IDoc mapper to reconcile inbound data with a remote system?

Use IF_EX_IDOC_DATA_MAPPER~PROCESS with early message-type gating, typed segment parsing, RFC destination resolution from the receiving port, local-vs-remote reconciliation, and explicit cleanup of only the remaining obsolete remote records. Keep the BAdI method thin, move compare logic into helpers, and handle RFC failures and logging explicitly.

Use IF_EX_IDOC_DATA_MAPPER~PROCESS with early message-type gating, typed segment parsing, RFC destination resolution from the receiving port, local-vs-remote reconciliation, and explicit cleanup of only the remaining obsolete remote records. Keep the BAdI method thin, move compare logic into helpers, and handle RFC failures and logging explicitly.

Implement the mapper as a thin `IF_EX_IDOC_DATA_MAPPER~PROCESS` orchestrator. First gate by message type, then read the relevant IDoc segment from `TAB_EDIDD`, cast `SDATA` to the expected structure, resolve the RFC destination from the receiving port, and compare local versus remote records by business key. Any remote records that remain after reconciliation are treated as obsolete and can be cleaned up one by one with explicit `system_failure` and `communication_failure` handling.

Process flow

  1. Gate execution by `control-mestyp` so the mapper runs only for the intended IDoc type.
  2. Read the relevant entry from `TAB_EDIDD` and verify `ls_data-segnam` matches the expected segment.
  3. Cast `SDATA` to the segment's typed structure and validate mandatory business-key fields.
  4. Resolve the RFC destination from the receiving port or routing configuration.
  5. Read the remote state through the RFC destination using a remote-enabled function module.
  6. Read the local source data with a key-focused selection.
  7. Remove matching entries from the remote candidate list using business-key comparison.
  8. Loop over the remaining remote entries and call the remote delete/update API with explicit exception handling.

Referenced tables

ObjectPurpose
TAB_EDIDDIDoc segment table used to read and parse the inbound segment payload
EDIPOAPort-to-RFC-destination mapping used for destination resolution

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example: idoc_mapper_complete_generalized_sample.abap

Exact relevant implementation excerpt from the knowledge document set.

1"============================================================================== 2" Complete Generalized IDoc Mapper Sample 3" Purpose: 4" - Demonstrate a full `IF_EX_IDOC_DATA_MAPPER~PROCESS` implementation pattern 5" - Parse inbound IDoc segment 6" - Resolve RFC destination 7" - Reconcile local and remote records 8" - Execute remote cleanup for obsolete entries 9"============================================================================== 10 11CLASS zcl_im_generic_idoc_mapper DEFINITION 12 PUBLIC 13 FINAL 14 CREATE PUBLIC. 15 16 PUBLIC SECTION. 17 INTERFACES if_ex_idoc_data_mapper. 18 19 PRIVATE SECTION. 20 TYPES: BEGIN OF ty_remote_record, 21 account_type TYPE koart, 22 account_id TYPE char20, 23 country TYPE banks, 24 bank_key TYPE bankl, 25 bank_account TYPE bankn, 26 END OF ty_remote_record. 27 28 TYPES tt_remote_record TYPE STANDARD TABLE OF ty_remote_record WITH DEFAULT KEY. 29 30 TYPES: BEGIN OF ty_local_record, 31 account_id TYPE char20, 32 country TYPE banks, 33 bank_key TYPE bankl, 34 bank_account TYPE bankn, 35 END OF ty_local_record. 36 37 TYPES tt_local_record TYPE STANDARD TABLE OF ty_local_record WITH DEFAULT KEY. 38 39 METHODS get_destination_by_port 40 IMPORTING 41 iv_port TYPE edi_rcvpor 42 RETURNING 43 VALUE(rv_destination) TYPE rfcdest. 44 45 METHODS read_remote_records 46 IMPORTING 47 iv_destination TYPE rfcdest 48 iv_account_id TYPE char20 49 RETURNING 50 VALUE(rt_remote) TYPE tt_remote_record. 51 52 METHODS read_local_records 53 IMPORTING 54 iv_account_id TYPE char20 55 RETURNING 56 VALUE(rt_local) TYPE tt_local_record. 57 58 METHODS reconcile_remote_against_local 59 IMPORTING 60 it_local TYPE tt_local_record 61 CHANGING 62 ct_remote TYPE tt_remote_record. 63 64 METHODS delete_remote_record 65 IMPORTING 66 iv_destination TYPE rfcdest 67 is_remote TYPE ty_remote_record. 68ENDCLASS. 69 70CLASS zcl_im_generic_idoc_mapper IMPLEMENTATION. 71 72 METHOD if_ex_idoc_data_mapper~process. 73 "------------------------------------------------------------ 74 " 1) Gate by message type so mapper runs only for target IDocs 75 "------------------------------------------------------------ 76 CHECK control-mestyp = 'ZCREMAS'. 77 78 "------------------------------------------------------------ 79 " 2) Read and validate the first segment payload 80 "------------------------------------------------------------ 81 READ TABLE data INTO DATA(ls_data) INDEX 1. 82 CHECK sy-subrc = 0. 83 CHECK ls_data-segnam = 'E1LFA1M'. 84 85 " Parse vendor segment payload. In productive code use the exact segment type. 86 DATA(ls_vendor_seg) = VALUE e1lfa1m( ls_data-sdata ). 87 CHECK ls_vendor_seg-lifnr IS NOT INITIAL. 88 89 "------------------------------------------------------------ 90 " 3) Resolve RFC destination from receiving port 91 "------------------------------------------------------------ 92 DATA(lv_destination) = get_destination_by_port( control-rcvpor ). 93 CHECK lv_destination IS NOT INITIAL. 94 95 "------------------------------------------------------------ 96 " 4) Read remote and local datasets for reconciliation 97 "------------------------------------------------------------ 98 DATA(lt_remote) = read_remote_records( 99 iv_destination = lv_destination 100 iv_account_id = ls_vendor_seg-lifnr ). 101 102 DATA(lt_local) = read_local_records( ls_vendor_seg-lifnr ). 103 104 "------------------------------------------------------------ 105 " 5) Remove matching records from remote list 106 " Remaining entries are obsolete in remote target 107 "------------------------------------------------------------ 108 reconcile_remote_against_local( 109 EXPORTING 110 it_local = lt_local 111 CHANGING 112 ct_remote = lt_remote ). 113 114 "------------------------------------------------------------ 115 " 6) Delete obsolete remote records 116 "------------------------------------------------------------ 117 LOOP AT lt_remote INTO DATA(ls_remote). 118 delete_remote_record( 119 iv_destination = lv_destination 120 is_remote = ls_remote ).

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

Related questions and keywords

Alternative questions

  • How do I build IF_EX_IDOC_DATA_MAPPER~PROCESS logic in SAP MDG?
  • How do I read IDoc segments, compare local and remote records, and clean up obsolete remote entries?
  • What is the recommended pattern for an IDoc mapper BAdI in MDG inbound processing?

Possible questions

  • How do I implement the IDoc mapper BAdI for inbound processing?
  • How do I parse TAB_EDIDD and validate the segment payload?
  • How do I resolve the RFC destination from the IDoc receiving port?
  • How do I compare local master data with remote records and delete obsolete ones?
  • How do I handle system_failure and communication_failure in the mapper?

Keywords

IF_EX_IDOC_DATA_MAPPER~PROCESSTAB_EDIDDSDATAEDIPOARFCDDESTsystem_failurecommunication_failureBALreconciliationmessage-type gating