SAP MDG · UTILITIES
How do I update the vendor account group in SAP MDG BP change data when the source account group changes?
Use the MDG change-data buffer to detect whether BP_CENTRL-ZZKTOKK changed, read the current BP header from the change request, then write the new value into BP_VENGEN-KTOKK with IO_WRITE.
Use the MDG change-data buffer to detect whether BP_CENTRL-ZZKTOKK changed, read the current BP header from the change request, then write the new value into BP_VENGEN-KTOKK with IO_WRITE.
Use the MDG change-data buffer to detect a changed BP central account group and propagate it to the vendor entity in the same change request. The source pattern reads BP_CENTRL, checks USMDX_S_UPDATE-ZZKTOKK, retrieves the BP from the change request, reads BP_VENGEN, updates KTOKK, and writes the modified data back with IO_WRITE.
Process flow
- Get the MDG application context with CL_USMD_APP_CONTEXT=>get_context( ).
- Get the BP model instance with CL_USMD_MODEL_EXT=>get_instance( ).
- Read changed BP_CENTRL data from IO_CHANGED_DATA.
- Check USMDX_S_UPDATE-ZZKTOKK to see whether the account group changed.
- Read the BP_HEADER entity from the current change request to derive the BP number.
- Create a data reference for BP_VENGEN with structure KATTR.
- Read BP_VENGEN for the BP number.
- Move the new account group into KTOKK for each vendor record and write it back with IO_WRITE->write_data( ).
Referenced tables
| Object | Purpose |
|---|---|
USMD1210 | Change request note table used by the related MDG utility method ADD_CREQUEST_NOTE. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1METHOD update_vendor_account_group.
2 CONSTANTS: lc_model TYPE usmd_model VALUE 'BP'.
3 DATA:
4 lt_entities TYPE usmd_t_crequest_entity,
5 lo_model_ext TYPE REF TO if_usmd_model_ext,
6 lv_partner TYPE bu_partner,
7 lv_entity TYPE usmd_entity,
8 lv_entity_name TYPE usmd_fieldname,
9 lo_data TYPE REF TO data,
10 lv_ktokk TYPE ktokk,
11 lv_acc_grp_changed TYPE boolean.
12
13 FIELD-SYMBOLS: <fs_t_centrl> TYPE ANY TABLE,
14 <fs_t_vengen> TYPE ANY TABLE,
15 <lfs_v_value> TYPE any.
16
17 DATA(lo_app_context) = cl_usmd_app_context=>get_context( ).
18 IF lo_app_context IS BOUND.
19 CALL METHOD cl_usmd_model_ext=>get_instance
20 EXPORTING
21 i_usmd_model = lc_model
22 IMPORTING
23 eo_instance = lo_model_ext.
24
25****************************
26 io_changed_data->read_data(
27 EXPORTING
28 i_entity = 'BP_CENTRL'
29 i_struct = if_usmd_model_ext=>gc_struct_key_attr " Type of Data Structure
30 IMPORTING
31 er_t_data_mod = DATA(lo_data_mod_bp_centrl)
32 ).
33 ASSIGN lo_data_mod_bp_centrl->* TO FIELD-SYMBOL(<fs_t_data_bp_centrl>) .
34 IF <fs_t_data_bp_centrl> IS ASSIGNED.
35 LOOP AT <fs_t_data_bp_centrl> ASSIGNING FIELD-SYMBOL(<fs_s_data_bp_centrl>).
36 ASSIGN COMPONENT 'USMDX_S_UPDATE' OF STRUCTURE <fs_s_data_bp_centrl> TO <lfs_v_value>.
37 IF <lfs_v_value> IS ASSIGNED.
38 ASSIGN COMPONENT 'ZZKTOKK' OF STRUCTURE <lfs_v_value> TO FIELD-SYMBOL(<lfs_acc_grp>).
39 IF <lfs_acc_grp> IS ASSIGNED.
40 lv_acc_grp_changed = <lfs_acc_grp>.
41 ENDIF.
42 UNASSIGN <lfs_v_value>.
43 ENDIF.
44 ASSIGN COMPONENT 'ZZKTOKK' OF STRUCTURE <fs_s_data_bp_centrl> TO <lfs_v_value>.
45 IF <lfs_v_value> IS ASSIGNED.
46 lv_ktokk = <lfs_v_value>.
47 ENDIF.
48 ENDLOOP.
49 ENDIF.
50****************************
51 IF lo_model_ext IS BOUND AND lv_acc_grp_changed = abap_true.
52*
53* CALL METHOD zcl_mdg_suppl_utility=>get_single_attribute
54* EXPORTING
55* im_crnumber = lo_app_context->mv_crequest_id
56* im_field = 'ZZKTOKD'
57* IMPORTING
58* ex_value = DATA(lv_accgrp).
59 CALL METHOD lo_model_ext->read_char_value
60 EXPORTING
61 i_fieldname = usmd0_cs_fld-crequest
62 it_sel = VALUE usmd_ts_sel( ( sign = 'I' option = 'EQ' fieldname = usmd0_cs_fld-crequest low = iv_cr_number ) )
63 IMPORTING
64 et_data = lt_entities.
65 LOOP AT lt_entities ASSIGNING FIELD-SYMBOL(<fs_entity>)
66 WHERE usmd_entity_obj = 'BP_HEADER'. "#EC CI_SORTSEQ
67 lv_partner = <fs_entity>-usmd_value.
68 ENDLOOP.
69 lv_entity = 'BP_VENGEN'.
70 lv_entity_name = lv_entity.
71 lo_model_ext->create_data_reference(
72 EXPORTING
73 i_fieldname = 'BP_VENGEN' " Field Name
74 i_struct = 'KATTR' " Structure
75 IMPORTING
76 er_data = lo_data
77 ).
78 ASSIGN lo_data->* TO <fs_t_vengen>.
79 IF <fs_t_vengen> IS ASSIGNED.
80 CALL METHOD lo_model_ext->read_char_value
81 EXPORTING
82 i_fieldname = lv_entity_name
83 it_sel = VALUE usmd_ts_sel( ( sign = usmd0_cs_ra-sign_i option = usmd0_cs_ra-option_eq fieldname = lv_entity low = lv_partner )
84 ( sign = usmd0_cs_ra-sign_i option = usmd0_cs_ra-option_eq fieldname = 'BP_HEADER' low = lv_partner ) )
85 IMPORTING
86 et_data = <fs_t_vengen>.
87 IF <fs_t_vengen> IS NOT INITIAL.
88 LOOP AT <fs_t_vengen> ASSIGNING FIELD-SYMBOL(<fs_s_vengen>).
89 ASSIGN COMPONENT 'KTOKK' OF STRUCTURE <fs_s_vengen> TO <lfs_v_value>.
90 IF <lfs_v_value> IS ASSIGNED.
91 <lfs_v_value> = lv_ktokk.
92 ENDIF.
93 UNASSIGN <lfs_v_value>.
94 ENDLOOP.
95 io_write->write_data(
96 i_entity = lv_entity " Entity Type
97 it_data = <fs_t_vengen>
98 ).
99* CATCH cx_usmd_write_error. " Error while writing to buffer
100 ENDIF.
101 ENDIF.
102
103 ENDIF.
104 ENDIF.
105ENDMETHOD.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How can I implement vendor account group derivation in MDG Business Partner?
- How do I copy the new BP account group into BP vendor data in MDG?
- What is the ABAP pattern to update BP_VENGEN-KTOKK in a change request?
Possible questions
- How do I update the vendor account group in SAP MDG BP change data when the source account group changes?
- How can I implement vendor account group derivation in MDG Business Partner?
- How do I copy the new BP account group into BP vendor data in MDG?
- What is the ABAP pattern to update BP_VENGEN-KTOKK in a change request?
- Which MDG APIs are used to read and write BP change data for vendor account group updates?