SAP MDG · DATA MODEL UI

How do I automatically populate the Material number in SAP MDG during create request processing?

Enhance the Material feeder’s `IF_FPM_GUIBB_FORM~GET_DATA` with an implicit enhancement, read the MDG change-request context, extract staged `MATKL`, generate the next number from the configured SNRO object/interval, convert it to `MATNR`, and set `EV_DATA_CHANGED` after updating `CS_DATA` and the feeder context.

Enhance the Material feeder’s `IF_FPM_GUIBB_FORM~GET_DATA` with an implicit enhancement, read the MDG change-request context, extract staged `MATKL`, generate the next number from the configured SNRO object/interval, convert it to `MATNR`, and set `EV_DATA_CHANGED` after updating `CS_DATA` and the feeder context.

Enhance the Material feeder’s `GET_DATA` method with an implicit enhancement and only generate `MATNR` when the current MDG change request is the configured create type, the key is still initial or a placeholder, and the staged Material Group (`MATKL`) is available. The standard pattern is to read the CR context, retrieve inactive Material data with `CL_USMD_MODEL_EXT=>GET_INSTANCE` and `READ_ENTITY_DATA_ALL`, derive the number-range interval from the first two characters of `MATKL`, call `NUMBER_GET_NEXT`, convert the result to internal `MATNR`, and finally update `CS_DATA` plus the feeder context before setting `EV_DATA_CHANGED`.

Process flow

  1. Read the MDG application context with `CL_USMD_APP_CONTEXT=>GET_CONTEXT`.
  2. Read `ev_crequest_type` and `ev_crequest_id` using `GET_ATTRIBUTES`.
  3. Exit unless the CR type matches the configured create type.
  4. Assign `MATNR` from `CS_DATA` and stop if it already contains a real value.
  5. Read inactive Material data with `CL_USMD_MODEL_EXT=>GET_INSTANCE` and `READ_ENTITY_DATA_ALL`.
  6. Extract staged `MATKL` dynamically from the returned entity table.
  7. Derive the number-range interval from the first two characters of `MATKL`.
  8. Call `NUMBER_GET_NEXT` for the configured SNRO object and interval.

Referenced tables

ObjectPurpose
usmd_crequestChange request identifier used by the local guard and runtime context.
usmd_ts_data_entityContainer for inactive staged entity data returned by `READ_ENTITY_DATA_ALL`.
usmd_t_messageMessage table returned by MDG model API calls.

ILLUSTRATIVE ABAP SAMPLE

Implicit enhancement for auto-populating MATNR in Material GET_DATA

Source-supported pattern. Replace the create CR type and number-range object with your configuration, and keep the feeder-sync call used in your release.

1CONSTANTS gc_create_cr_type TYPE usmd_crequest_type VALUE 'ZMAT01'. 2CONSTANTS gc_nr_object TYPE inri-object VALUE 'ZMDG_MM'. 3 4STATICS gv_last_crequest TYPE usmd_crequest. 5 6DATA lo_context TYPE REF TO if_usmd_app_context. 7DATA lo_model_ext TYPE REF TO if_usmd_model_ext. 8DATA lt_data_entity TYPE usmd_ts_data_entity. 9DATA lt_message TYPE usmd_t_message. 10DATA lv_matkl TYPE matkl. 11DATA lv_interval TYPE inri-nrrangenr. 12DATA lv_number TYPE char20. 13DATA lv_matnr TYPE matnr. 14 15FIELD-SYMBOLS <lt_entity_data> TYPE ANY TABLE. 16FIELD-SYMBOLS <ls_entity_data> TYPE any. 17FIELD-SYMBOLS <lv_matkl> TYPE any. 18FIELD-SYMBOLS <lv_matnr> TYPE any. 19 20lo_context = cl_usmd_app_context=>get_context( ). 21IF lo_context IS NOT BOUND. 22 RETURN. 23ENDIF. 24 25lo_context->get_attributes( 26 IMPORTING 27 ev_crequest_type = DATA(lv_crequest_type) 28 ev_crequest_id = DATA(lv_crequest) ). 29 30IF lv_crequest IS INITIAL OR lv_crequest_type <> gc_create_cr_type. 31 RETURN. 32ENDIF. 33 34ASSIGN COMPONENT 'MATNR' OF STRUCTURE cs_data TO <lv_matnr>. 35IF sy-subrc <> 0 OR <lv_matnr> IS NOT ASSIGNED. 36 RETURN. 37ENDIF. 38 39IF <lv_matnr> IS NOT INITIAL AND <lv_matnr> NP '$*'. 40 RETURN. 41ENDIF. 42 43IF gv_last_crequest = lv_crequest. 44 RETURN. 45ENDIF. 46 47cl_usmd_model_ext=>get_instance( 48 EXPORTING 49 i_usmd_model = 'MM' 50 IMPORTING 51 eo_instance = lo_model_ext 52 et_message = lt_message ). 53 54IF lo_model_ext IS NOT BOUND. 55 RETURN. 56ENDIF. 57 58lo_model_ext->read_entity_data_all( 59 EXPORTING 60 i_fieldname = 'MATERIAL' 61 if_active = abap_false 62 i_crequest = lv_crequest 63 IMPORTING 64 et_message = lt_message 65 et_data_entity = lt_data_entity ). 66 67LOOP AT lt_data_entity INTO DATA(ls_data_entity). 68 ASSIGN ls_data_entity-r_t_data->* TO <lt_entity_data>. 69 IF sy-subrc <> 0. 70 CONTINUE. 71 ENDIF. 72 73 LOOP AT <lt_entity_data> ASSIGNING <ls_entity_data>. 74 UNASSIGN <lv_matkl>. 75 ASSIGN COMPONENT 'MATKL' OF STRUCTURE <ls_entity_data> TO <lv_matkl>. 76 IF sy-subrc = 0 AND <lv_matkl> IS NOT INITIAL. 77 lv_matkl = <lv_matkl>. 78 EXIT. 79 ENDIF. 80 ENDLOOP. 81 82 IF lv_matkl IS NOT INITIAL. 83 EXIT. 84 ENDIF. 85ENDLOOP. 86 87IF lv_matkl IS INITIAL. 88 RETURN. 89ENDIF. 90 91lv_interval = lv_matkl(2). 92 93CALL FUNCTION 'NUMBER_GET_NEXT' 94 EXPORTING 95 nr_range_nr = lv_interval 96 object = gc_nr_object 97 quantity = 1 98 IMPORTING 99 number = lv_number 100 EXCEPTIONS 101 interval_not_found = 1 102 number_range_not_intern = 2 103 object_not_found = 3 104 quantity_is_0 = 4 105 quantity_is_not_1 = 5 106 interval_overflow = 6 107 buffer_overflow = 7 108 OTHERS = 8. 109 110IF sy-subrc <> 0. 111 RETURN. 112ENDIF. 113 114CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' 115 EXPORTING 116 input = lv_number 117 IMPORTING 118 output = lv_matnr. 119 120<lv_matnr> = lv_matnr. 121mo_context->set_attribute( 122 EXPORTING 123 iv_name = 'MATNR' 124 iv_value = lv_matnr ). 125 126gv_last_crequest = lv_crequest. 127ev_data_changed = abap_true.

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

Related questions and keywords

Alternative questions

  • How can I auto-generate MATNR in an MDG create change request?
  • Which feeder class and method should I enhance to fill MATNR automatically?
  • How do I derive the Material number from the material group in MDG?

Possible questions

  • How can I auto-generate MATNR in an MDG create change request?
  • Which feeder class and method should I enhance to fill MATNR automatically?
  • How do I derive the Material number from the material group in MDG?
  • How do I prevent MATNR from being overwritten after it is assigned?
  • How do I read staged MATKL data in an MDG Material create request?

Keywords

MATNRMATKLCL_USMD_APP_CONTEXTCL_USMD_MODEL_EXTREAD_ENTITY_DATA_ALLNUMBER_GET_NEXTCONVERSION_EXIT_MATN1_INPUTIF_FPM_GUIBB_FORM~GET_DATA/PLMU/CL_FRW_G_FEEDER_FORMUSMD_CREQUESTUSMD_CREQUEST_TYPE