SAP MDG · VALIDATION DERIVATION

How do I implement SAP MDG derivation so material descriptions are built from classification values in IF_EX_USMD_RULE_SERVICE2~DERIVE?

Use a derivation BAdI implementation on IF_EX_USMD_RULE_SERVICE2~DERIVE to read changed valuation data, merge it with existing classification values, build the description text, and write the updated material text data back to the MDG change buffer.

Use a derivation BAdI implementation on IF_EX_USMD_RULE_SERVICE2~DERIVE to read changed valuation data, merge it with existing classification values, build the description text, and write the updated material text data back to the MDG change buffer.

Use a derivation BAdI implementation on IF_EX_USMD_RULE_SERVICE2~DERIVE. The source example class CL_MDG_BS_MAT_CLF2DESCRIPTION shows the full pattern: resolve internal characteristic IDs for IB_TYPE and IB_COLOR, read only changed valuation data from io_changed_data, merge changed and existing values, build the description text, and update the material entity through the MDG write buffer. Below are the exact implementation steps and the source-supported ABAP pattern.

Process flow

  1. Create the MDG rule-service BAdI implementation and bind an implementing class.
  2. Implement IF_EX_USMD_RULE_SERVICE2 in the class.
  3. Resolve internal characteristic IDs for IB_TYPE and IB_COLOR in CLASS_CONSTRUCTOR using GET_ATINN.
  4. In DERIVE, read changed valuation rows from io_changed_data for entity valuation.
  5. Collect the affected MATNR values from the changed rows.
  6. For each material, detect whether IB_TYPE and/or IB_COLOR changed.
  7. Read current classification with READ_CLASSIFICATION when at least one relevant characteristic changed.
  8. Merge changed and existing values to form the final description text. Use CONCATENATE lv_value1 ': ' lv_value2 INTO lv_description. Create the material text data reference, fill language rows, and write back through io_write_data->write_dat

Referenced tables

ObjectPurpose
CABNCharacteristic master data table used by CLSE_SELECT_CABN_VIA_NAME to resolve ATINN from characteristic name.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example

Exact relevant implementation excerpt from the knowledge document.

1class CL_MDG_BS_MAT_CLF2DESCRIPTION definition 2 public 3 final 4 create public . 5 6public section. 7 8 interfaces IF_BADI_INTERFACE . 9 interfaces IF_EX_USMD_RULE_SERVICE2 . 10 11 class-methods CLASS_CONSTRUCTOR . 12protected section. 13private section. 14 15 types: 16 ty_valuation_tab TYPE STANDARD TABLE OF /mdgmm/_s_mm_pp_valuation WITH DEFAULT KEY . 17 18 constants GC_CLASSTYPE type KLASSENART value '001'. "#EC NOTEXT 19 constants GC_CHARNAME1 type ATNAM value 'IB_TYPE'. "#EC NOTEXT 20 constants GC_CHARNAME2 type ATNAM value 'IB_COLOR'. "#EC NOTEXT 21 class-data GV_CHARID1 type MDG_BS_CLF_CHARID . 22 class-data GV_CHARID2 type MDG_BS_CLF_CHARID . 23 24 class-methods READ_CLASSIFICATION 25 importing 26 !IV_MATNR type MATNR 27 !IV_CLASSTYPE type KLASSENART 28 !IO_MODEL type ref to IF_USMD_MODEL_EXT 29 returning 30 value(RT_VALUATION) type TY_VALUATION_TAB 31 raising 32 CX_MDG_BS_MAT_GEN . 33 class-methods GET_ATINN 34 importing 35 !IV_CHARNAME type ATNAM 36 returning 37 value(RV_CHARID) type ATINN . 38ENDCLASS. 39 40 41 42CLASS CL_MDG_BS_MAT_CLF2DESCRIPTION IMPLEMENTATION. 43 44 45method CLASS_CONSTRUCTOR. 46 " Get the internal characteristic IDs 47 gv_charid1 = get_atinn( gc_charname1 ). 48 gv_charid2 = get_atinn( gc_charname2 ). 49endmethod. 50 51 52METHOD get_atinn. 53 DATA: lt_cabn TYPE STANDARD TABLE OF cabn. 54 DATA: ls_cabn TYPE cabn. 55 CLEAR rv_charid. 56 ASSERT iv_charname <> space. 57 " Read internal characteristic ID from characteristic name 58 CALL FUNCTION 'CLSE_SELECT_CABN_VIA_NAME' 59 EXPORTING 60 characteristic = iv_charname 61 TABLES 62 t_cabn = lt_cabn 63 EXCEPTIONS 64 OTHERS = 0. 65 READ TABLE lt_cabn INTO ls_cabn INDEX 1. 66 rv_charid = ls_cabn-atinn. 67ENDMETHOD. 68 69 70METHOD if_ex_usmd_rule_service2~derive. 71* Merges the valuation of two characteristics (hard-coded on IDs) into description 72* Assumptions: 73* - No change number 74* - No multi-value characteristics 75 DATA: lt_valuation TYPE ty_valuation_tab. 76 DATA: ls_valuation TYPE /mdgmm/_s_mm_pp_valuation. 77 DATA: lr_exc TYPE REF TO cx_mdg_bs_mat_gen. 78 DATA: ls_message TYPE usmd_s_message. 79 DATA: lr_mod TYPE REF TO data. 80 DATA: lt_attribute TYPE usmd_ts_fieldname. 81 DATA: lrt_entity_data TYPE REF TO data. 82 DATA: ls_description TYPE /mdgmm/_st_mm_pp_material. 83 DATA: lv_description TYPE usmd_txtmi. 84 DATA: lv_found1 TYPE abap_bool. 85 DATA: lv_found2 TYPE abap_bool. 86 DATA: lv_value1 TYPE atwrt. 87 DATA: lv_value2 TYPE atwrt. 88 DATA: lt_matnr TYPE SORTED TABLE OF matnr WITH UNIQUE KEY table_line. 89 DATA: lr_descr_struc TYPE REF TO data. 90 DATA: lo_structdescr TYPE REF TO cl_abap_structdescr. 91 FIELD-SYMBOLS: <lf_component> TYPE abap_compdescr. 92 FIELD-SYMBOLS: <lt_description> TYPE STANDARD TABLE. 93 FIELD-SYMBOLS: <ls_description> TYPE any. 94 FIELD-SYMBOLS: <lt_mod> TYPE SORTED TABLE. 95 FIELD-SYMBOLS: <ls_mod> TYPE any. 96 FIELD-SYMBOLS: <lv_matnr> TYPE matnr. 97 CLEAR: et_message_info. 98 " Only consider changed valuations 99 CALL METHOD io_changed_data->read_data 100 EXPORTING 101 i_entity = if_mdg_bs_mat_gen_c=>gc_entity_valuation 102 IMPORTING 103 er_t_data_mod = lr_mod. 104 CHECK lr_mod IS BOUND. 105 ASSIGN lr_mod->* TO <lt_mod>. 106 CHECK sy-subrc = 0 AND <lt_mod> IS ASSIGNED AND <lt_mod> IS NOT INITIAL. 107 " Get the material numbers 108 LOOP AT <lt_mod> ASSIGNING <ls_mod>. 109 ASSIGN COMPONENT if_mdg_bs_mat_gen_c=>gc_attr_material OF STRUCTURE <ls_mod> TO <lv_matnr>. 110 INSERT <lv_matnr> INTO TABLE lt_matnr. 111 ENDLOOP. 112 " Derive description for all changed materials 113 LOOP AT lt_matnr ASSIGNING <lv_matnr>. 114 CLEAR: lv_value1, lv_value2, lv_found1, lv_found2. 115 " Get the changed classification values 116 " if the two characteristics have been changed for the current material 117 LOOP AT <lt_mod> ASSIGNING <ls_mod>. 118 MOVE-CORRESPONDING <ls_mod> TO ls_valuation. 119 CHECK ls_valuation-material = <lv_matnr>. 120 IF ls_valuation-charid = gv_charid1.

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

Related questions and keywords

Alternative questions

  • How do I derive a material description from classification characteristics in SAP MDG?
  • How is IF_EX_USMD_RULE_SERVICE2~DERIVE implemented for material classification in MDG?
  • How can I update the material description when IB_TYPE or IB_COLOR changes?

Possible questions

  • Which BAdI and method are used for MDG derivation?
  • How do I read changed classification data in a derivation BAdI?
  • How do I get internal characteristic IDs from characteristic names?
  • How do I write derived material description data back to the MDG change buffer?
  • What class implements the material classification-to-description derivation example?

Keywords

SAP MDGABAPIF_EX_USMD_RULE_SERVICE2DERIVEclassificationmaterial descriptionCL_MDG_BS_MAT_CLF2DESCRIPTIONCLSE_SELECT_CABN_VIA_NAMECABNUSMD_MODEL_EXT