SAP MDG · DATA MODEL UI
How do I auto-populate G/L Account main keys in SAP MDG during create change requests?
Enhance the G/L Account feeder in `IF_FPM_GUIBB_FORM~GET_DATA` and fill `COA`, `ACCOUNT`, `TXTSH`, and `TXTLG` only in the create change request type. Use `CL_USMD_APP_CONTEXT` to read the CR context, guard against overwriting existing values, update both `CS_DATA` and the feeder attribute buffer, and set `EV_DATA_CHANGED` after assignment.
Enhance the G/L Account feeder in `IF_FPM_GUIBB_FORM~GET_DATA` and fill `COA`, `ACCOUNT`, `TXTSH`, and `TXTLG` only in the create change request type. Use `CL_USMD_APP_CONTEXT` to read the CR context, guard against overwriting existing values, update both `CS_DATA` and the feeder attribute buffer, and set `EV_DATA_CHANGED` after assignment.
Enhance `CL_MDGF_GUIBB_FI_ACCOUNT->IF_FPM_GUIBB_FORM~GET_DATA` with an implicit enhancement and generate the G/L Account key only when the current change request is the configured create CR type. The source pattern reads the CR context via `CL_USMD_APP_CONTEXT`, builds a temporary key from the change request number, and fills `CS_DATA` plus the feeder buffer so MDG accepts the value consistently.
Process flow
- Open the active implementation of `CL_MDGF_GUIBB_FI_ACCOUNT`.
- Enhance `IF_FPM_GUIBB_FORM~GET_DATA` with an implicit enhancement at the end of the method.
- Read CR context using `CL_USMD_APP_CONTEXT=>GET_CONTEXT` and `GET_ATTRIBUTES`.
- Exit if the CR is missing or the CR type is not the configured create type.
- Strip leading zeros from the CR ID if you derive the temporary account from the CR number.
- Assign `COA`, `ACCOUNT`, `TXTSH`, and `TXTLG` only when the target field is initial.
- Call `me->set_access_attribute` after each assignment so the feeder buffer is updated.
- Set `EV_DATA_CHANGED = ABAP_TRUE` only if at least one field changed.
Referenced tables
| Object | Purpose |
|---|---|
— No table-based configuration is specified in the retrieved source for this key-population pattern. |
ILLUSTRATIVE ABAP SAMPLE
G/L Account auto-population in MDG create mode
Source-based sample adapted from the retrieved `gl-account-get-data.abap` pattern. Replace the constants with your configured create CR type, chart of accounts, and prefix.
1CONSTANTS gc_create_cr_type TYPE usmd_crequest_type VALUE 'ZACC1P1'.
2CONSTANTS gc_chart_of_accounts TYPE ktopl VALUE '0001'.
3CONSTANTS gc_key_prefix TYPE char4 VALUE 'TEMP'.
4
5DATA lo_context TYPE REF TO if_usmd_app_context.
6DATA lv_crequest_text TYPE string.
7DATA lv_changed TYPE abap_bool.
8
9FIELD-SYMBOLS <lv_coa> TYPE any.
10FIELD-SYMBOLS <lv_account> TYPE any.
11FIELD-SYMBOLS <lv_short_text> TYPE any.
12FIELD-SYMBOLS <lv_long_text> TYPE any.
13
14lo_context = cl_usmd_app_context=>get_context( ).
15IF lo_context IS NOT BOUND.
16 RETURN.
17ENDIF.
18
19lo_context->get_attributes(
20 IMPORTING
21 ev_crequest_type = DATA(lv_crequest_type)
22 ev_crequest_id = DATA(lv_crequest) ).
23
24IF lv_crequest IS INITIAL OR lv_crequest_type <> gc_create_cr_type.
25 RETURN.
26ENDIF.
27
28lv_crequest_text = lv_crequest.
29SHIFT lv_crequest_text LEFT DELETING LEADING '0'.
30
31ASSIGN COMPONENT 'COA' OF STRUCTURE cs_data TO <lv_coa>.
32IF sy-subrc = 0 AND <lv_coa> IS ASSIGNED AND <lv_coa> IS INITIAL.
33 <lv_coa> = gc_chart_of_accounts.
34 me->set_access_attribute(
35 io_access = me->mo_entity
36 iv_attr_name = 'COA'
37 iv_value = <lv_coa> ).
38 lv_changed = abap_true.
39ENDIF.
40
41ASSIGN COMPONENT 'ACCOUNT' OF STRUCTURE cs_data TO <lv_account>.
42IF sy-subrc = 0 AND <lv_account> IS ASSIGNED AND <lv_account> IS INITIAL.
43 <lv_account> = |{ gc_key_prefix }{ lv_crequest_text }|.
44 me->set_access_attribute(
45 io_access = me->mo_entity
46 iv_attr_name = 'ACCOUNT'
47 iv_value = <lv_account> ).
48 lv_changed = abap_true.
49ENDIF.
50
51ASSIGN COMPONENT 'TXTSH' OF STRUCTURE cs_data TO <lv_short_text>.
52IF sy-subrc = 0 AND <lv_short_text> IS ASSIGNED AND <lv_short_text> IS INITIAL.
53 <lv_short_text> = 'Short Text for G/L Account'.
54 me->set_access_attribute(
55 io_access = me->mo_entity
56 iv_attr_name = 'TXTSH'
57 iv_value = <lv_short_text> ).
58 lv_changed = abap_true.
59ENDIF.
60
61ASSIGN COMPONENT 'TXTLG' OF STRUCTURE cs_data TO <lv_long_text>.
62IF sy-subrc = 0 AND <lv_long_text> IS ASSIGNED AND <lv_long_text> IS INITIAL.
63 <lv_long_text> = 'Long Text for G/L Account'.
64 me->set_access_attribute(
65 io_access = me->mo_entity
66 iv_attr_name = 'TXTLG'
67 iv_value = <lv_long_text> ).
68 lv_changed = abap_true.
69ENDIF.
70
71IF lv_changed = abap_true.
72 ev_data_changed = abap_true.
73ENDIF.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How can I derive the G/L Account number automatically in MDG create mode?
- What is the ABAP enhancement for auto-filling ACCOUNT in SAP MDG?
- How do I populate COA, ACCOUNT, TXTSH, and TXTLG automatically in MDG?
Possible questions
- Can I use the change request number to build a temporary G/L Account key in MDG?
- Which feeder class and method should I enhance for auto-populating G/L Account keys?
- How do I ensure the auto-generated key is written to both CS_DATA and the feeder buffer?
- What guard conditions should I use so the key is only generated once per change request?
- How do I adapt the sample for a different create CR type or key prefix?