SAP MDG · REPLICATION OUTBOUND
How do I implement a configuration-driven SAP MDG DRF filter class with dynamic key extraction and optional account-group specialization?
Implement IF_DRF_FILTER~APPLY_FILTER so it reads filter rules by replication object and business system, optionally enriches them with context-specific rules, then removes excluded entries from ET_FILTERED_OBJECTS using dynamic key extraction and index-safe deletion.
Implement IF_DRF_FILTER~APPLY_FILTER so it reads filter rules by replication object and business system, optionally enriches them with context-specific rules, then removes excluded entries from ET_FILTERED_OBJECTS using dynamic key extraction and index-safe deletion.
Use a configuration-driven IF_DRF_FILTER~APPLY_FILTER implementation: read the main rules by object and target business system, optionally enrich with context-specific rules, extract the object key dynamically from the first component of each filtered row, and delete rows whose rule has SIGN = 'E'. The pattern stays safe when the extra context is missing, so the base filter still runs.
Process flow
- Read main filter configuration by replication object and business system.
- Optionally determine specialized context such as account group or object type.
- Merge the generic and specialized rule sets into an effective configuration.
- Loop through ET_FILTERED_OBJECTS and extract the object key dynamically from the first structure component.
- Delete rows whose effective rule has SIGN = 'E'.
- Continue with the base configuration if context enrichment is unavailable.
Referenced tables
| Object | Purpose |
|---|---|
z_filter_cfg | Main filter rule table used to read entries by object and business system. |
ztt_filter_cfg | Typed internal table structure used for specialized filter rules in the example pattern. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example: generic_filter_code_sample.abap
Exact relevant implementation excerpt from the knowledge document set.
1"==============================================================================
2" Generic Filter Code Sample
3" Purpose:
4" - Demonstrate a configurable filter implementation using the DRF pattern
5" - Show dynamic key extraction from generic structures
6" - Show fallback behavior when specialized context is unavailable
7"==============================================================================
8
9CLASS zcl_generic_filter_sample DEFINITION
10 PUBLIC
11 FINAL
12 CREATE PUBLIC.
13
14 PUBLIC SECTION.
15 INTERFACES if_drf_filter.
16
17 PROTECTED SECTION.
18 PRIVATE SECTION.
19
20 TYPES: BEGIN OF ty_cfg,
21 fobj TYPE char10,
22 business_system TYPE char60,
23 value TYPE char40,
24 sign TYPE c LENGTH 1,
25 END OF ty_cfg.
26
27 TYPES tt_cfg TYPE STANDARD TABLE OF ty_cfg WITH DEFAULT KEY.
28
29 METHODS get_main_config
30 IMPORTING
31 is_c_fobj TYPE drffobj
32 iv_business_system TYPE drf_system_alias
33 RETURNING
34 VALUE(rt_cfg) TYPE tt_cfg.
35
36 METHODS get_specific_config
37 IMPORTING
38 is_c_fobj TYPE drffobj
39 iv_business_system TYPE drf_system_alias
40 iv_object_group TYPE char20
41 RETURNING
42 VALUE(rt_cfg) TYPE tt_cfg.
43
44 METHODS resolve_object_group
45 IMPORTING
46 is_c_fobj TYPE drffobj
47 RETURNING
48 VALUE(rv_group) TYPE char20.
49
50 METHODS merge_effective_rules
51 IMPORTING
52 it_main TYPE tt_cfg
53 it_specific TYPE tt_cfg
54 RETURNING
55 VALUE(rt_effective) TYPE tt_cfg.
56ENDCLASS.
57
58CLASS zcl_generic_filter_sample IMPLEMENTATION.
59
60 METHOD if_drf_filter~apply_filter.
61 "------------------------------------------------------------
62 " 1) Read base configuration by object + business system
63 "------------------------------------------------------------
64 DATA(lt_main_cfg) = get_main_config(
65 is_c_fobj = is_c_fobj
66 iv_business_system = iv_business_system ).
67
68 " If no rules are configured, keep all objects as-is.
69 IF lt_main_cfg IS INITIAL.
70 RETURN.
71 ENDIF.
72
73 "------------------------------------------------------------
74 " 2) Resolve context-specific classification (optional)
75 "------------------------------------------------------------
76 DATA(lv_group) = resolve_object_group( is_c_fobj = is_c_fobj ).
77
78 "------------------------------------------------------------
79 " 3) Load specialized rules and merge with base rules
80 "------------------------------------------------------------
81 DATA(lt_specific_cfg) = VALUE tt_cfg( ).
82 IF lv_group IS NOT INITIAL.
83 lt_specific_cfg = get_specific_config(
84 is_c_fobj = is_c_fobj
85 iv_business_system = iv_business_system
86 iv_object_group = lv_group ).
87 ENDIF.
88
89 DATA(lt_effective_cfg) = merge_effective_rules(
90 it_main = lt_main_cfg
91 it_specific = lt_specific_cfg ).
92
93 "------------------------------------------------------------
94 " 4) Apply filter to outgoing object list
95 "------------------------------------------------------------
96 LOOP AT et_filtered_objects ASSIGNING FIELD-SYMBOL(<ls_object_row>).
97 DATA(lv_index) = sy-tabix.
98
99 " DRF payload is generic, so get business key dynamically from component 1.
100 ASSIGN COMPONENT 1 OF STRUCTURE <ls_object_row> TO FIELD-SYMBOL(<lv_object_key>).
101 IF <lv_object_key> IS NOT ASSIGNED.
102 CONTINUE.
103 ENDIF.
104
105 DATA(lv_key_value) = CONV char40( <lv_object_key> ).
106
107 READ TABLE lt_effective_cfg INTO DATA(ls_rule)
108 WITH KEY value = lv_key_value.
109 IF sy-subrc = 0 AND ls_rule-sign = 'E'.
110 " Exclusion rule found: remove object from replication list.
111 DELETE et_filtered_objects INDEX lv_index.
112 ENDIF.
113 ENDLOOP.
114
115 ENDMETHOD.
116
117 METHOD get_main_config.
118 " Replace this SELECT with your productive configuration table.
119 " Example pattern:
120 " SELECT * FROM zmdg_drf_config INTO TABLE @rt_cfgThe remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How do I build an IF_DRF_FILTER~APPLY_FILTER implementation for MDG outbound filtering?
- How can I reduce DRF outbound payload in SAP MDG using custom filter logic?
- How do I add fallback-safe context-aware filtering to a Z*FILTER* class?
Possible questions
- How do I implement a configuration-driven SAP MDG DRF filter class with dynamic key extraction and optional account-group specialization?
- How do I build an IF_DRF_FILTER~APPLY_FILTER implementation for MDG outbound filtering?
- How can I reduce DRF outbound payload in SAP MDG using custom filter logic?
- How do I add fallback-safe context-aware filtering to a Z*FILTER* class?
- How do I keep DRF filtering deterministic when context enrichment is missing?