SAP MDG · VALIDATION DERIVATION

How do I implement cross-entity derivation for class assignments in SAP MDG for Material?

Use BAdI `USMD_RULE_SERVICE_CROSS_ET` and implement `IF_EX_USMD_RULE_SERVICE2~DERIVE`. In the provided example, the derivation runs only for CR type `MATL01`, steps `00` and `90`, only when no class assignment exists yet, and derives class assignment from `EXTWG` when it matches a class of class type `001`.

Use BAdI `USMD_RULE_SERVICE_CROSS_ET` and implement `IF_EX_USMD_RULE_SERVICE2~DERIVE`. In the provided example, the derivation runs only for CR type `MATL01`, steps `00` and `90`, only when no class assignment exists yet, and derives class assignment from `EXTWG` when it matches a class of class type `001`.

Use BAdI `USMD_RULE_SERVICE_CROSS_ET` with class `CL_MDG_MAT_CLASSASGN_CROSS_ET` and method `IF_EX_USMD_RULE_SERVICE2~DERIVE`. The example checks the change request context, reads the current material and `EXTWG` from the delta buffer, validates that a class of class type `001` exists in `KLAH`, ensures no class assignment already exists, then writes the derived class assignment back to the delta buffer and adds an info message.

Process flow

  1. Open SE18 and display BAdI `USMD_RULE_SERVICE_CROSS_ET`.
  2. Create or edit the implementation in SE19.
  3. Assign a custom implementing class and activate it.
  4. Implement `IF_EX_USMD_RULE_SERVICE2~DERIVE`.
  5. Check `io_model` and application context for model, CR type, and CR step.
  6. Read current material data from `io_changed_data`.
  7. Derive the class from `EXTWG` and validate it in `KLAH` with class type `001`.
  8. Check that no class assignment already exists in delta/persisted data before writing.

Referenced tables

ObjectPurpose
KLAHUsed in the example to verify that the derived class exists for class type `001`.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example

Exact relevant implementation excerpt from the knowledge document.

1class CL_MDG_MAT_CLASSASGN_CROSS_ET definition 2 public 3 final 4 create public . 5 6public section. 7 8 interfaces IF_BADI_INTERFACE . 9 interfaces IF_EX_USMD_RULE_SERVICE2 . 10protected section. 11private section. 12ENDCLASS. 13 14 15 16CLASS CL_MDG_MAT_CLASSASGN_CROSS_ET IMPLEMENTATION. 17 18 19METHOD if_ex_usmd_rule_service2~derive. 20*! Example implementation for cross entity derivations for MDG for Material with Class Assignments. 21* 22* The derivation shall only take place 23* - if change request type is MATL01 (Create Material w. Lean Classification) 24* - if change request step is 00 (Processing) or 90 (Final Check) 25* - if no class is assigned yet 26* - if an external material group exists, and that group corresponds to a class (of class type 001). This is 27* just a simple example and should be replaced by a meaningful usecase. 28* 29* The change request information is taken from the application context, the material and external material group is read 30* via the delta buffer. The check, if class assignments were already done, is performed via data model and delta buffer. 31* 32* The BAdI is called at least once at every roundtrip (Technical note: the BAdI is triggered in the Flush Method of the Governance API). 33* - Valid for Single Item Maintenance UI and Data import 34* - Messages from Derives are always converted into info messages. 35* - The BAdI gets only the attributes that are changed since the last BAdI call. Unchanged attributes are not transferred by the 36* interface of this BAdI. You need to use the IO_MODEL parameter (method READ_CHAR_VALUE or RETRIEVE_CHAR_VALUE) to determine 37* their values. For more information, see the documentation of the interface IF_USMD_MODEL_EXT. 38* Hint: Set parameter IF_NO_FLUSH to ABAP_TRUE to avoid additional call of the Flush Method 39 40 41 CONSTANTS: 42 lc_classtype TYPE klassenart VALUE '001', "Material Class 43 lc_crequest_type TYPE usmd_crequest_type VALUE 'MATL01', "Create Material with Lean Classification 44 lc_crequest_step_final TYPE usmd_crequest_wfs VALUE '90', "Final Check 45 lc_crequest_step_proc TYPE usmd_crequest_wfs VALUE '00'. "Processing 46 47 DATA: 48 lv_class TYPE klasse_d, 49 lv_crequest_type TYPE usmd_crequest_type, 50 lv_crequest_step TYPE usmd_crequest_wfs, 51 lo_usmd_app_context TYPE REF TO if_usmd_app_context, 52 lv_material TYPE matnr, 53 lv_ext_mat_group TYPE extwg, 54 lt_sel TYPE usmd_ts_sel, 55 ls_sel LIKE LINE OF lt_sel, 56 lrt_material TYPE REF TO data, 57 lrt_data_mod TYPE REF TO data, 58 lrt_classasgn TYPE REF TO data, 59 lrs_classasgn TYPE REF TO data, 60 ls_klah TYPE klah, 61 lt_attribute TYPE usmd_ts_fieldname, 62 lo_structdescr TYPE REF TO cl_abap_structdescr, 63 lt_message TYPE usmd_t_message, 64 ls_message LIKE LINE OF lt_message, 65 lv_message TYPE string. "#EC NEEDED 66 67 FIELD-SYMBOLS: 68 <lt_material> TYPE SORTED TABLE, 69 <ls_material> TYPE any, 70 <lt_classasgn> TYPE SORTED TABLE, 71 <ls_classasgn> TYPE any, 72 <lv_material> TYPE matnr, 73 <lv_ext_mat_group> TYPE extwg, 74 <lv_class> TYPE klasse_d, 75 <lv_classtype> TYPE klassenart, 76 <lv_clint> TYPE clint, 77 <lv_component> TYPE abap_compdescr. 78 79 CLEAR et_message_info. 80 81 "Check if the data model is correct. Should not happen if the BAdI filter value is set correctly. 82 IF io_model IS INITIAL 83 OR io_model->d_usmd_model <> if_mdg_bs_mat_gen_c=>gc_model_mm. 84 RETURN. 85 ENDIF. 86 87 "Retrieve change request information via application context 88 lo_usmd_app_context = cl_usmd_app_context=>get_context( ). 89 90 IF lo_usmd_app_context IS INITIAL. 91 RETURN. 92 ENDIF. 93 94 "Do the derivation only for the correct change request type 95 lo_usmd_app_context->get_attributes( IMPORTING ev_crequest_type = lv_crequest_type ). 96 IF lv_crequest_type <> lc_crequest_type. 97 RETURN. 98 ENDIF. 99 100 "Do the derivation only during the correct change request steps 101 lo_usmd_app_context->get_attributes( IMPORTING ev_crequest_step = lv_crequest_step ). 102 IF lv_crequest_step <> lc_crequest_step_final 103 AND lv_crequest_step <> lc_crequest_step_proc. 104 RETURN. 105 ENDIF. 106 107 "Determine the current entity data, this means the material number and external material group. 108 "It is needed to read the correct class assignment information. 109 io_changed_data->read_data( 110 EXPORTING 111 i_entity = if_mdg_bs_mat_gen_c=>gc_entity_material 112 IMPORTING 113 er_t_data_mod = lrt_material ). 114 115 IF lrt_material IS INITIAL. 116 RETURN. 117 ENDIF. 118 119 ASSIGN lrt_material->* TO <lt_material>. 120 IF <lt_material> IS NOT ASSIGNED

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

Related questions and keywords

Alternative questions

  • How can I derive a material class from the external material group in MDG-M?
  • Which BAdI is used for cross-entity derivation in MDG for Material?
  • How do I add a class assignment automatically in an MDG material change request?

Possible questions

  • How do I implement cross-entity derivation for class assignments in SAP MDG for Material?
  • How can I derive a material class from the external material group in MDG-M?
  • Which BAdI is used for cross-entity derivation in MDG for Material?
  • How do I add a class assignment automatically in an MDG material change request?
  • What is the exact ABAP example for CL_MDG_MAT_CLASSASGN_CROSS_ET?

Keywords

SAP MDG-Mcross-entity derivationUSMD_RULE_SERVICE_CROSS_ETIF_EX_USMD_RULE_SERVICE2~DERIVEclass assignmentmaterial classificationMATL01EXTWGKLAHCLINTKLARTdelta buffer