SAP MDG · DATA MODEL UI
How do I auto-populate the Profit Center key in SAP MDG during create change request processing?
Implement an implicit enhancement at the end of `CL_MDGF_GUIBB_PCTR->IF_FPM_GUIBB_FORM~GET_DATA`, read the MDG change request context, and populate `COAREA` and `PCTR` only for create change requests of type `ZPCT1P2`. Use `NUMBER_GET_NEXT` for the Profit Center number range, prefix it with `P`, call `set_access_attribute`, and set `EV_DATA_CHANGED` after assignment.
Implement an implicit enhancement at the end of `CL_MDGF_GUIBB_PCTR->IF_FPM_GUIBB_FORM~GET_DATA`, read the MDG change request context, and populate `COAREA` and `PCTR` only for create change requests of type `ZPCT1P2`. Use `NUMBER_GET_NEXT` for the Profit Center number range, prefix it with `P`, call `set_access_attribute`, and set `EV_DATA_CHANGED` after assignment.
Implement the Profit Center auto-numbering in an implicit enhancement at the end of `CL_MDGF_GUIBB_PCTR->IF_FPM_GUIBB_FORM~GET_DATA`. The pattern reads the MDG application context, exits unless the current change request type is `ZPCT1P2`, defaults `COAREA` when needed, generates the next SNRO number from `ZMDG_PCTR` / interval `01`, adds prefix `P`, updates `CS_DATA`, and marks the data as changed.
Process flow
- Open `CL_MDGF_GUIBB_PCTR` and enhance `IF_FPM_GUIBB_FORM~GET_DATA` at the end of the standard implementation.
- Read the MDG application context with `CL_USMD_APP_CONTEXT=>GET_CONTEXT` and fetch CR type and CR ID.
- Exit unless the CR type equals `ZPCT1P2` and the CR ID is available.
- Populate `COAREA` only if it is initial, then call `set_access_attribute` for `COAREA`.
- Populate `PCTR` only if it is initial and the same CR has not already been processed.
- Call `NUMBER_GET_NEXT` for object `ZMDG_PCTR`, interval `01`, quantity `1`.
- Prefix the returned number with `P`, assign it to `CS_DATA-PCTR`, and call `set_access_attribute` for `PCTR`.
- Store the processed CR in the local `STATICS` guard and set `EV_DATA_CHANGED = ABAP_TRUE`.
Referenced tables
| Object | Purpose |
|---|---|
USMD_CREQUEST | Change request identifier used in the CR guard |
INRI_OBJECT | Number range object type used by `NUMBER_GET_NEXT` |
INRI_NRRANGENR | Number range interval type used by `NUMBER_GET_NEXT` |
ILLUSTRATIVE ABAP SAMPLE
Profit Center auto-population in `CL_MDGF_GUIBB_PCTR->IF_FPM_GUIBB_FORM~GET_DATA`
Source-adapted sample using the exact values from the retrieved implementation. Keep the implicit enhancement at the end of the standard method.
1CONSTANTS gc_create_cr_type TYPE usmd_crequest_type VALUE 'ZPCT1P2'.
2CONSTANTS gc_controlling_area TYPE kokrs VALUE '0001'.
3CONSTANTS gc_nr_object TYPE inri-object VALUE 'ZMDG_PCTR'.
4CONSTANTS gc_nr_interval TYPE inri-nrrangenr VALUE '01'.
5CONSTANTS gc_key_prefix TYPE char1 VALUE 'P'.
6
7STATICS gv_last_crequest TYPE usmd_crequest.
8
9DATA lo_context TYPE REF TO if_usmd_app_context.
10DATA lv_number TYPE char20.
11DATA lv_new_pctr TYPE prctr.
12DATA lv_changed TYPE abap_bool.
13
14FIELD-SYMBOLS <lv_coarea> TYPE any.
15FIELD-SYMBOLS <lv_pctr> TYPE any.
16
17lo_context = cl_usmd_app_context=>get_context( ).
18IF lo_context IS NOT BOUND.
19 RETURN.
20ENDIF.
21
22lo_context->get_attributes(
23 IMPORTING
24 ev_crequest_type = DATA(lv_crequest_type)
25 ev_crequest_id = DATA(lv_crequest) ).
26
27IF lv_crequest IS INITIAL OR lv_crequest_type <> gc_create_cr_type.
28 RETURN.
29ENDIF.
30
31ASSIGN COMPONENT 'COAREA' OF STRUCTURE cs_data TO <lv_coarea>.
32IF sy-subrc = 0 AND <lv_coarea> IS ASSIGNED AND <lv_coarea> IS INITIAL.
33 <lv_coarea> = gc_controlling_area.
34 me->set_access_attribute(
35 io_access = me->mo_entity
36 iv_attr_name = 'COAREA'
37 iv_value = <lv_coarea> ).
38 lv_changed = abap_true.
39 ev_data_changed = abap_true.
40ENDIF.
41
42ASSIGN COMPONENT 'PCTR' OF STRUCTURE cs_data TO <lv_pctr>.
43IF sy-subrc <> 0 OR <lv_pctr> IS NOT ASSIGNED OR <lv_pctr> IS NOT INITIAL.
44 RETURN.
45ENDIF.
46
47IF gv_last_crequest = lv_crequest.
48 RETURN.
49ENDIF.
50
51CALL FUNCTION 'NUMBER_GET_NEXT'
52 EXPORTING
53 nr_range_nr = gc_nr_interval
54 object = gc_nr_object
55 quantity = 1
56 IMPORTING
57 number = lv_number
58 EXCEPTIONS
59 interval_not_found = 1
60 number_range_not_intern = 2
61 object_not_found = 3
62 quantity_is_0 = 4
63 quantity_is_not_1 = 5
64 interval_overflow = 6
65 buffer_overflow = 7
66 OTHERS = 8.
67
68IF sy-subrc <> 0.
69 IF lv_changed = abap_true.
70 ev_data_changed = abap_true.
71 ENDIF.
72 RETURN.
73ENDIF.
74
75CONDENSE lv_number NO-GAPS.
76lv_new_pctr = |{ gc_key_prefix }{ lv_number }|.
77<lv_pctr> = lv_new_pctr.
78
79me->set_access_attribute(
80 io_access = me->mo_entity
81 iv_attr_name = 'PCTR'
82 iv_value = lv_new_pctr ).
83
84gv_last_crequest = lv_crequest.
85ev_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 generate PCTR automatically in CL_MDGF_GUIBB_PCTR GET_DATA?
- What is the SAP MDG enhancement for automatic Profit Center number assignment?
- How do I populate controlling area and Profit Center automatically in MDG create requests?
Possible questions
- How do I auto-populate the Profit Center key in SAP MDG during create change request processing?
- How can I generate PCTR automatically in CL_MDGF_GUIBB_PCTR GET_DATA?
- What is the SAP MDG enhancement for automatic Profit Center number assignment?
- How do I populate controlling area and Profit Center automatically in MDG create requests?
- How do I implement SNRO-based Profit Center generation in MDG?