SAP MDG · VALIDATION DERIVATION
How do I implement SAP MDG derivation logic to read CR context, assign default values only when a field is initial, and derive a search term from a name field?
Use a reusable derivation helper class: read the change request context via `zcl_mdg_suppl_utility=>get_cr_details`, assign a field only if it is initial with dynamic component access, append returned messages safely, and derive `BU_SORT1` from `NAME_ORG1` by removing special characters and converting the result to uppercase.
Use a reusable derivation helper class: read the change request context via `zcl_mdg_suppl_utility=>get_cr_details`, assign a field only if it is initial with dynamic component access, append returned messages safely, and derive `BU_SORT1` from `NAME_ORG1` by removing special characters and converting the result to uppercase.
A practical SAP MDG derivation pattern is to keep the logic in small reusable helper methods: one method reads the change request context, one method assigns a value only when a target field is initial, one method appends messages, and one method derives a search term from a name field. The sample below shows exactly how to do this with dynamic field access and a standard function module for special-character cleanup.
Process flow
- Create or reuse a helper class for derivation utilities.
- Implement `read_context` to call `zcl_mdg_suppl_utility=>get_cr_details` and return CR ID, CR type, and CR step.
- Implement `assign_if_initial` with `ASSIGN COMPONENT iv_field OF STRUCTURE cs_row TO <lv_field>` and write only when the component is initial.
- Implement `append_messages` by appending all rows from the source message table to the target table and clearing the source.
- Implement `derive_search_term` by reading `NAME_ORG1` and `BU_SORT1`, removing special characters from the source name, taking the first 10 characters, and converting them to uppercase.
- Call these helpers from your MDG derivation logic where appropriate.
Referenced tables
| Object | Purpose |
|---|---|
USMD_T_MESSAGE | Message table used to collect derivation or validation messages. |
ILLUSTRATIVE ABAP SAMPLE
Reusable SAP MDG derivation helper class
Source-supported ABAP pattern for reading CR context, assigning a value only when a field is initial, appending messages, and deriving BU_SORT1 from NAME_ORG1.
1CLASS zcl_usmd_derivation_skill DEFINITION
2 PUBLIC
3 FINAL
4 CREATE PUBLIC.
5
6 PUBLIC SECTION.
7 CLASS-METHODS read_context
8 EXPORTING ev_crequest_id TYPE usmd_crequest
9 ev_crequest_type TYPE usmd_crequest_type
10 ev_crequest_step TYPE usmd_crequest_appstep.
11
12 CLASS-METHODS assign_if_initial
13 CHANGING cs_row TYPE any
14 IMPORTING iv_field TYPE fieldname
15 iv_value TYPE any.
16
17 CLASS-METHODS append_messages
18 CHANGING ct_target TYPE usmd_t_message
19 ct_source TYPE usmd_t_message.
20
21 CLASS-METHODS derive_search_term
22 CHANGING cs_row TYPE any.
23ENDCLASS.
24
25CLASS zcl_usmd_derivation_skill IMPLEMENTATION.
26
27 METHOD read_context.
28 zcl_mdg_suppl_utility=>get_cr_details(
29 IMPORTING
30 ev_crequest_id = ev_crequest_id
31 ev_crequest_type = ev_crequest_type
32 ev_crequest_step = ev_crequest_step ).
33 ENDMETHOD.
34
35 METHOD assign_if_initial.
36 FIELD-SYMBOLS <lv_field> TYPE any.
37 ASSIGN COMPONENT iv_field OF STRUCTURE cs_row TO <lv_field>.
38 IF <lv_field> IS ASSIGNED AND <lv_field> IS INITIAL.
39 <lv_field> = iv_value.
40 ENDIF.
41 ENDMETHOD.
42
43 METHOD append_messages.
44 IF ct_source IS NOT INITIAL.
45 APPEND LINES OF ct_source TO ct_target.
46 CLEAR ct_source.
47 ENDIF.
48 ENDMETHOD.
49
50 METHOD derive_search_term.
51 FIELD-SYMBOLS: <lv_name_org1> TYPE any,
52 <lv_bu_sort1> TYPE any.
53
54 ASSIGN COMPONENT 'NAME_ORG1' OF STRUCTURE cs_row TO <lv_name_org1>.
55 ASSIGN COMPONENT 'BU_SORT1' OF STRUCTURE cs_row TO <lv_bu_sort1>.
56
57 IF <lv_name_org1> IS ASSIGNED AND <lv_name_org1> IS NOT INITIAL
58 AND <lv_bu_sort1> IS ASSIGNED AND <lv_bu_sort1> IS INITIAL.
59
60 CALL FUNCTION 'SF_SPECIALCHAR_DELETE'
61 EXPORTING
62 with_specialchar = <lv_name_org1>
63 IMPORTING
64 without_specialchar = DATA(lv_org_name).
65
66 IF sy-subrc = 0.
67 <lv_bu_sort1> = lv_org_name+0(10).
68 TRANSLATE <lv_bu_sort1> TO UPPER CASE.
69 ENDIF.
70 ENDIF.
71 ENDMETHOD.
72
73ENDCLASS.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How do I implement reusable SAP MDG derivation helper methods for context read, conditional assignment, message append, and search-term derivation?
- How do I derive BU_SORT1 from NAME_ORG1 in SAP MDG only when BU_SORT1 is initial?
- How do I read the change request context in a custom SAP MDG derivation class?
Possible questions
- How do I implement reusable SAP MDG derivation helper methods for context read, conditional assignment, message append, and search-term derivation?
- How do I derive BU_SORT1 from NAME_ORG1 in SAP MDG only when BU_SORT1 is initial?
- How do I read the change request context in a custom SAP MDG derivation class?
- Which ABAP helper methods are useful for SAP MDG derivations?
- What is the pattern for generic field assignment in SAP MDG derivation logic?