SAP MDG · REPLICATION INBOUND
How do I implement an IDoc data mapper BAdI to enrich or clean inbound data during processing?
Use `IF_EX_IDOC_DATA_MAPPER~PROCESS` to gate by message type, read and validate the target IDoc segment, resolve the RFC destination from the receiving port via `EDIPOA`, read remote and local datasets, remove matching remote entries, and call the remote cleanup API for the remaining obsolete records.
Use `IF_EX_IDOC_DATA_MAPPER~PROCESS` to gate by message type, read and validate the target IDoc segment, resolve the RFC destination from the receiving port via `EDIPOA`, read remote and local datasets, remove matching remote entries, and call the remote cleanup API for the remaining obsolete records.
The standard pattern for an inbound IDoc mapper is to keep `IF_EX_IDOC_DATA_MAPPER~PROCESS` thin and let helper methods handle parsing, destination lookup, comparison, and remote cleanup. It starts with message-type gating, then reads the inbound segment from `DATA`, resolves the RFC destination from the receiving port, loads remote and local records, and removes any remote entries that still exist locally.
Process flow
- Determine the target message type and segment.
- Implement `IF_EX_IDOC_DATA_MAPPER~PROCESS` in a custom class.
- Read `DATA` and validate `SEGNAM` and mandatory fields.
- Resolve the RFC destination from `CONTROL-RCVPOR` using `EDIPOA`.
- Read remote data from the destination system.
- Read corresponding local data in the current system.
- Remove matching remote entries from the candidate list.
- Call the remote delete or update API for what remains.
IDoc port to RFC destination mapping
Resolve the destination system from the inbound IDoc receiving port
Referenced tables
| Object | Purpose |
|---|---|
EDIPOA | Maps IDoc ports to logical destinations for RFC lookup |
TAB_EDIDD | Inbound IDoc segment table used to read and validate segment data |
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 an IF_EX_IDOC_DATA_MAPPER~PROCESS implementation?
- What is the standard pattern for an inbound IDoc mapper BAdI?
- How do I reconcile inbound IDoc data against local and remote master data?
Possible questions
- How do I implement an IDoc data mapper BAdI to enrich or clean inbound data during processing?
- How do I parse IDoc segments and resolve the RFC destination in an IDoc mapper?
- How do I compare local and remote records in IF_EX_IDOC_DATA_MAPPER~PROCESS?
- How do I delete obsolete remote records from an inbound IDoc mapper?
- What is the recommended error handling pattern for an IDoc mapper BAdI?