SAP MDG · UTILITIES
How do I read MDG Business Partner entity data and flatten non-empty fields into an output list?
Use `CL_USMD_MODEL_EXT=>GET_INSTANCE` and `IF_USMD_MODEL_EXT~READ_ENTITY_DATA_ALL` to read `BP_HEADER` from the MDG model, then loop over `USMD_TS_DATA_ENTITY`, dereference `R_T_DATA`, and use `ASSIGN COMPONENT` to flatten each non-initial field into entity/field/field text/value rows.
Use `CL_USMD_MODEL_EXT=>GET_INSTANCE` and `IF_USMD_MODEL_EXT~READ_ENTITY_DATA_ALL` to read `BP_HEADER` from the MDG model, then loop over `USMD_TS_DATA_ENTITY`, dereference `R_T_DATA`, and use `ASSIGN COMPONENT` to flatten each non-initial field into entity/field/field text/value rows.
Use the MDG model API to read `BP_HEADER` from the change request, choose staging or active read based on the CR status, then flatten each populated component into a generic output structure with entity, field, field text, and value.
Process flow
- Read `
USMD_CREQ_STATUS` from `USMD120C` for the input change request. - Instantiate the MDG model extension for model `BP` using `CL_USMD_MODEL_EXT=>GET_INSTANCE`.
- For non-active CRs, call `READ_ENTITY_DATA_ALL` with `I_FIELDNAME = 'BP_HEADER'`, `IF_ACTIVE = space`, and `I_CREQUEST = iv_cr`.
- For active CRs, resolve the BP key and build `
USMD_TS_SEL` for `BP_HEADER`, then call `READ_ENTITY_DATA_ALL` with `IF_ACTIVE = 'X'`. - Loop over the returned `
USMD_TS_DATA_ENTITY` rows. - Dereference `R_T_DATA` and inspect the generic internal table row by row.
- Use `CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_DATA( )` and `GET_COMPONENTS( )` to determine field names at runtime.
- Use `ASSIGN COMPONENT` to read each field value and skip initial values only when they are not populated in the source row object used for flattening.
USMD120C
Read the change request status and branch between staging and active data read.
Model = BP, Entity = BP_HEADER
Read Business Partner entity data through the MDG model API.
Referenced tables
| Object | Purpose |
|---|---|
USMD120C | Change request header/status table used to determine whether to read staging or active data. |
USMD_TS_DATA_ENTITY | Returned MDG entity-data result block used for dynamic flattening. |
USMD_TS_SEL | Selection table used when reading active data for a specific BP key. |
ILLUSTRATIVE ABAP SAMPLE
Flatten MDG BP entity data into entity/field/value rows
Source-supported sample based on the documented pattern. Replace the customer-specific CR key helper if needed in your system.
1CLASS zcl_entity_data_flatten_reader DEFINITION PUBLIC FINAL CREATE PUBLIC.
2 PUBLIC SECTION.
3 TYPES: BEGIN OF ty_read_data,
4 entity TYPE string,
5 field TYPE string,
6 field_desc TYPE string,
7 value TYPE string,
8 END OF ty_read_data.
9 TYPES tt_read_data TYPE TABLE OF ty_read_data.
10
11 CLASS-METHODS read_data
12 IMPORTING iv_cr TYPE usmd_crequest
13 EXPORTING et_data TYPE tt_read_data.
14ENDCLASS.
15
16CLASS zcl_entity_data_flatten_reader IMPLEMENTATION.
17 METHOD read_data.
18 DATA: go_model_ext TYPE REF TO if_usmd_model_ext,
19 gt_data TYPE usmd_ts_data_entity.
20
21 SELECT SINGLE usmd_creq_status INTO @DATA(lv_stat)
22 FROM usmd120c
23 WHERE usmd_crequest = @iv_cr.
24
25 cl_usmd_model_ext=>get_instance(
26 EXPORTING i_usmd_model = 'BP'
27 IMPORTING eo_instance = go_model_ext ).
28
29 IF lv_stat <> '05' AND lv_stat <> '06'.
30 CALL METHOD go_model_ext->read_entity_data_all
31 EXPORTING
32 i_fieldname = 'BP_HEADER'
33 if_active = ''
34 i_crequest = iv_cr
35 IMPORTING
36 et_data_entity = gt_data.
37 ELSE.
38 CALL METHOD zcl_mdg_suppl_utility=>get_cr_key
39 EXPORTING iv_crequest = iv_cr
40 IMPORTING ev_key_if_single = DATA(lv_bp).
41
42 IF lv_bp IS NOT INITIAL.
43 DATA lt_sel TYPE usmd_ts_sel.
44 APPEND VALUE #( fieldname = 'BP_HEADER' low = lv_bp sign = 'I' option = 'EQ' ) TO lt_sel.
45
46 CALL METHOD go_model_ext->read_entity_data_all
47 EXPORTING
48 i_fieldname = 'BP_HEADER'
49 if_active = 'X'
50 it_sel = lt_sel
51 IMPORTING
52 et_data_entity = gt_data.
53 ENDIF.
54 ENDIF.
55
56 FIELD-SYMBOLS: <fs_tab> TYPE ANY TABLE,
57 <fs_row> TYPE any,
58 <fs_field> TYPE any.
59
60 LOOP AT gt_data INTO DATA(ls_ac_data).
61 ASSIGN ls_ac_data-r_t_data->* TO <fs_tab>.
62 LOOP AT <fs_tab> ASSIGNING <fs_row>.
63 DATA(lo_descr) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( <fs_row> ) ).
64 DATA(lt_components) = lo_descr->get_components( ).
65
66 DO lines( lt_components ) TIMES.
67 DATA(lv_index) = sy-index.
68 ASSIGN COMPONENT lv_index OF STRUCTURE <fs_row> TO <fs_field>.
69 IF <fs_field> IS ASSIGNED AND <fs_field> IS NOT INITIAL.
70 DATA(ls_out) = VALUE ty_read_data(
71 entity = COND #( WHEN ls_ac_data-usmd_entity_cont IS NOT INITIAL
72 THEN ls_ac_data-usmd_entity_cont
73 ELSE ls_ac_data-usmd_entity )
74 field = lt_components[ lv_index ]-name
75 value = <fs_field> ).
76
77 TRY.
78 ls_out-field_desc = go_model_ext->dt_entity_attr_prop[ attr_res = ls_out-field ]-r_fprop->scrtext_m.
79 CATCH cx_sy_itab_line_not_found.
80 ls_out-field_desc = ls_out-field.
81 ENDTRY.
82
83 APPEND ls_out TO et_data.
84 ENDIF.
85 ENDDO.
86 ENDLOOP.
87 ENDLOOP.
88
89 DELETE ADJACENT DUPLICATES FROM et_data.
90 ENDMETHOD.
91ENDCLASS.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How can I extract BP_HEADER data from an MDG change request and list only populated fields?
- What is the reusable ABAP pattern for flattening MDG entity data into entity/field/text/value rows?
- How do I read active versus staging MDG data for Business Partner and get field descriptions?
Possible questions
- How do I read MDG Business Partner entity data and flatten non-empty fields into an output list?
- How do I convert MDG entity data into a generic table of field/value pairs?
- How do I read active BP data for a change request and flatten it for display?
- How do I get field texts while iterating over MDG entity attributes?
- How do I choose between active and staging reads in MDG?