SAP MDG · VALIDATION DERIVATION

How do I implement SAP MDG address/postal derivation in the derivation exit so fields like language, region, and postal code are defaulted from the change request context?

Implement the address/postal derivation as a context-driven defaulting routine: read the current change request and BP header from the MDG model, loop over CT_DATA, and set only initial fields such as language, region, or postal code based on CR type and step.

Implement the address/postal derivation as a context-driven defaulting routine: read the current change request and BP header from the MDG model, loop over CT_DATA, and set only initial fields such as language, region, or postal code based on CR type and step.

Implement the address/postal derivation as a small, context-aware defaulting routine. The source pattern reads the current change request with CL_USMD_APP_CONTEXT and CL_USMD_CREQUEST_API, fetches BP_HEADER via io_model->read_entity_data_all, and then updates CT_DATA only when target fields are initial. In the provided example, the logic defaults language to 'E' for CR type ZSUPINT1 and applies Brazilian postal defaults when the request is in step '00'.

Process flow

  1. Open the MDG derivation implementation for the address/postal hook.
  2. Read CR context with CL_USMD_APP_CONTEXT=>GET_CONTEXT( ) and GET_ATTRIBUTES( ).
  3. Read the current change request with CL_USMD_CREQUEST_API=>GET_INSTANCE and READ_CREQUEST.
  4. Assign CT_DATA to a generic field-symbol table.
  5. Read BP_HEADER via IO_MODEL->READ_ENTITY_DATA_ALL using entity filter BP_HEADER.
  6. Loop over CT_DATA and default only initial fields with ASSIGN COMPONENT.
  7. Apply CR-type and step-based conditions before writing values.
  8. Activate and test the derivation with the relevant MDG business process.

Referenced tables

ObjectPurpose
USMD_T_ENTITYEntity filter table used when reading BP_HEADER data from the MDG model.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example

Exact relevant implementation excerpt from the knowledge document.

1* Purpose: Interface hook for address/postal derivation. 2 3 METHOD zif_te_derivation~d_ad_postal. 4 DATA:lt_filter TYPE usmd_t_entity, 5 wa_filter LIKE LINE OF lt_filter. 6 7 CONSTANTS: lc_header TYPE usmd_fieldname VALUE 'BP_HEADER'. 8 9 FIELD-SYMBOLS: <fs_t_data_bp_header> TYPE ANY TABLE, 10 <fs_t_data_bp_compny> TYPE ANY TABLE, 11 <fs_t_data> TYPE ANY TABLE, 12 <fs_data> TYPE any. 13 14 DATA(lo_context) = cl_usmd_app_context=>get_context( ). 15 CHECK lo_context IS BOUND. 16 17 lo_context->get_attributes( IMPORTING ev_crequest_id = DATA(lv_crequest_id) 18 ev_crequest_step = DATA(lv_crequest_step) ). 19 20 cl_usmd_crequest_api=>get_instance( 21 EXPORTING 22 iv_crequest = lv_crequest_id 23 iv_model_name = zif_bp_constants=>data_model-bp " Data Model 24 IMPORTING 25 et_message = et_message " Messages 26 re_inst_crequest_api = DATA(lo_crequest) " Change Request API Interface 27 ). 28 lo_crequest->read_crequest( 29 IMPORTING 30 es_crequest = DATA(ls_crequest) " Change Request 31 ). 32 33 ASSIGN ct_data TO <fs_t_data>. 34 35* Get Header Details 36 wa_filter = zif_bp_constants=>entity_type-bp_header. 37 INSERT wa_filter INTO TABLE lt_filter. 38 io_model->read_entity_data_all( 39 EXPORTING 40 i_fieldname = lc_header 41 if_active = abap_false 42 i_crequest = ls_crequest-usmd_crequest 43 it_entity_filter = lt_filter 44 IMPORTING 45 et_message = DATA(lt_et_message) " Messages 46 et_data_entity = DATA(lt_data_bp_header) " Data for Entity Types 47 ). 48 DATA ls_data_bp_header LIKE LINE OF lt_data_bp_header. 49 IF lt_data_bp_header IS NOT INITIAL. 50 READ TABLE lt_data_bp_header INTO ls_data_bp_header WITH KEY usmd_entity = zif_bp_constants=>bp_header-bp_header. 51 IF sy-subrc EQ 0. 52 ASSIGN ls_data_bp_header-r_t_data->* TO <fs_t_data_bp_header>. 53 ENDIF. 54 ENDIF. 55 IF <fs_t_data_bp_header> IS ASSIGNED. 56 LOOP AT <fs_t_data_bp_header> ASSIGNING FIELD-SYMBOL(<fs_bp_header>). 57 ASSIGN COMPONENT zif_bp_constants=>bp_header-bu_group OF STRUCTURE <fs_bp_header> TO FIELD-SYMBOL(<fs_ktokk>). 58 ENDLOOP. 59 ENDIF. 60 61 LOOP AT <fs_t_data> ASSIGNING <fs_data>. 62* Derive language as E for ZSUPINT1 CR type 63 IF id_crequest_type = zif_bp_constants=>creq_type-zsupint1. 64 ASSIGN COMPONENT zif_bp_constants=>ad_postal-langu_com OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_langu>). 65 IF <fs_langu> IS ASSIGNED AND <fs_langu> IS INITIAL. 66 <fs_langu> = 'E'. 67 ENDIF. 68 ENDIF. 69* Begin of Insert by TE579309. 70 IF lv_crequest_step = '00'. 71 ASSIGN COMPONENT zif_bp_constants=>ad_postal-ref_posta OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_ref_posta>). 72 IF sy-subrc IS INITIAL AND <fs_ref_posta> IS ASSIGNED AND <fs_ref_posta> = 'BR'. 73 ASSIGN COMPONENT zif_bp_constants=>ad_postal-rfe_post OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_rfe_post>). 74 IF sy-subrc IS INITIAL AND <fs_rfe_post> IS ASSIGNED. 75 <fs_rfe_post> = 'SP'. 76 ENDIF. 77 ASSIGN COMPONENT zif_bp_constants=>ad_postal-post_cod1 OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_post_cod1>). 78 IF sy-subrc IS INITIAL AND <fs_post_cod1> IS ASSIGNED. 79 <fs_post_cod1> = '01001-000'. 80 ENDIF. 81 ENDIF. 82 ENDIF. 83* End of Insert by TE579309 84 ENDLOOP. 85 ENDMETHOD. 86 87 88 89* Generic note: custom helper calls in this method are documented by role in the paired knowledge note. 90* Generic note: small constants and selector literals are business-rule markers, not separate logic.

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

Related questions and keywords

Alternative questions

  • How can I derive AD_POSTAL fields in SAP MDG based on CR type and step?
  • What is the implementation pattern for address/postal derivation in MDG BP?
  • How do I default postal address fields only when they are initial in SAP MDG?

Possible questions

  • How do I implement SAP MDG address/postal derivation in the derivation exit so fields like language, region, and postal code are defaulted from the change request context?
  • How do I default AD_POSTAL fields only when they are initial in SAP MDG?
  • How do I read BP header and change request details inside a derivation method?
  • What is the step-by-step setup for a BAdI implementation for MDG derivation?
  • How do I implement an address derivation hook for BP in ABAP?

Keywords

SAP MDGABAPderivationAD_POSTALBP_HEADERUSMD_RULE_SERVICEIF_EX_USMD_RULE_SERVICETE derivationCL_USMD_APP_CONTEXTCL_USMD_CREQUEST_APIio_model->read_entity_data_allCT_DATAdefaultschange requestpostal codelanguage