SAP MDG · WORKFLOWS

How do I implement an SAP MDG dynamic agent BAdI for supplier workflow routing with activation and GTS handling?

Implement IF_USMD_SSW_DYNAMIC_AGT_SELECT~GET_DYNAMIC_AGENTS to read the CR context, call your approver logic, populate user or non-user agent groups, and switch to a technical GTS step when the request reaches activation.

Implement IF_USMD_SSW_DYNAMIC_AGT_SELECT~GET_DYNAMIC_AGENTS to read the CR context, call your approver logic, populate user or non-user agent groups, and switch to a technical GTS step when the request reaches activation.

Dynamic-agent BAdI implementations in SAP MDG determine approvers at runtime instead of relying only on static workflow tables. In the supplier example, the class reads the CR number, calls a custom approver resolver, fills CT_USER_AGENT_GROUP for normal approval, and switches to a technical non-user step for activation/GTS processing when CV_NEW_STEP reaches 91.

Process flow

  1. Create the dynamic-agent class and implement IF_USMD_SSW_DYNAMIC_AGT_SELECT.
  2. Check IV_SERVICE_NAME and run only the intended workflow branch.
  3. Read approvers from your custom logic.
  4. Fill CT_USER_AGENT_GROUP for dialog approvers.
  5. Set STEP_TYPE according to the next business action.
  6. If activation or GTS is required, clear the dialog agents and fill CT_NON_USER_AGENT_GROUP.
  7. Read the CR type from the application context or USMD120C if needed.
  8. Set CV_NEW_STEP and CV_NEW_CR_STATUS consistently before returning.

Referenced tables

ObjectPurpose
USMD120CFallback source for the change request type when the application context is not bound.
TVARVCStores the allowed CR types used to decide whether the GTS technical step should run.
DEMO_EXPRESSIONSExample table updated in the sample to persist a flag for the activation branch.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example

Exact relevant implementation excerpt from the knowledge document.

1class ZCL_MDG_SUP_DYN_AGENT definition 2 public 3 final 4 create public . 5 6public section. 7 8 interfaces IF_BADI_INTERFACE . 9 interfaces IF_USMD_SSW_DYNAMIC_AGT_SELECT . 10protected section. 11private section. 12 13 class-methods READ_MATERIAL 14 importing 15 !IV_CR_NUMBER type USMD_CREQUEST 16 exporting 17 !ES_MATERIAL type /MDGMM/_S_MM_PP_MATERIAL . 18 class-methods READ_CR_OBJECTLIST 19 importing 20 !IO_MODEL type ref to IF_USMD_MODEL_EXT 21 !IV_CREQUEST_ID type USMD_CREQUEST 22 returning 23 value(RT_OBJLIST) type USMD_T_CREQUEST_ENTITY . 24ENDCLASS. 25 26 27 28CLASS ZCL_MDG_SUP_DYN_AGENT IMPLEMENTATION. 29 30 31METHOD if_usmd_ssw_dynamic_agt_select~get_dynamic_agents. 32 DATA: lt_users TYPE ztt_mdg_supl_appr, 33 ls_user_agent_group TYPE usmd_s_user_agent_group, 34 ls_user_agent TYPE usmd_s_user_agent, 35 ls_non_user TYPE usmd_s_non_user_agent_group, 36 lv_buff TYPE xstring. 37 DATA: lv_act1 TYPE boolean VALUE abap_false. 38* Clear exporting parameter 39 CLEAR et_message. 40 41 CASE iv_service_name. 42 WHEN 'ZMDG_SUP_DYN_AGENT'. 43* Read the approvers from Custom Table and get the workflow steps 44 CALL METHOD zcl_mdg_sup_approvers_sup2=>get_sup_approvers 45 EXPORTING 46 iv_cr_number = iv_cr_number 47 iv_system_id = 'SUPPLIER_SET_UP' 48 IMPORTING 49 et_approvers = lt_users 50 ev_change_flg = DATA(lv_change_flag) 51 CHANGING 52 cv_new_step = cv_new_step 53 cv_new_cr_status = cv_new_cr_status. 54 55 IF cv_new_step = '91'. 56 CLEAR ct_user_agent_group. 57 CLEAR: ct_non_user_agent_group. 58 cv_new_step = '91'. 59 cv_new_cr_status = '02'. 60 ls_non_user-agent_group = 1. 61 ls_non_user-process_pattern = '06'. 62 APPEND ls_non_user TO ct_non_user_agent_group. 63 DATA(lv_act) = abap_true. 64 EXPORT lv_act = lv_act TO DATA BUFFER lv_buff. 65 MODIFY demo_expressions FROM @( 66 VALUE #( id = 'E' numc1 = iv_cr_number xstring1 = lv_buff ) ). 67 ELSEIF lt_users[] IS NOT INITIAL. 68 CLEAR ct_user_agent_group. 69 ls_user_agent_group-agent_group = 1. 70 71 IF cv_new_cr_status = 04. 72 ls_user_agent_group-step_type = 'X'. " Approve 73 ELSE. 74 ls_user_agent_group-step_type = '3'. " finalize 75 ENDIF. 76 77 LOOP AT lt_users INTO DATA(ls_users). 78 79 CLEAR: ls_user_agent. 80 ls_user_agent-user_type = 'US'. 81 ls_user_agent-user_value = ls_users-user_id. 82 APPEND ls_user_agent TO ls_user_agent_group-user_agent. 83 ENDLOOP. 84 APPEND ls_user_agent_group TO ct_user_agent_group. 85 ENDIF. 86 IF cv_new_step = '91'. 87 lv_act1 = abap_true. 88 ENDIF. 89 ENDCASE. 90* * SOC by TE581834 for GTS call before activation step 91 IF lv_act1 = abap_true. 92 DATA: lo_app_context TYPE REF TO if_usmd_app_context, 93 lv_crequest_type TYPE usmd_crequest_type. 94 95 lo_app_context = cl_usmd_app_context=>get_context( ). 96 IF lo_app_context IS BOUND. 97 lv_crequest_type = lo_app_context->mv_crequest_type. 98 ELSE. 99 SELECT SINGLE usmd_creq_type FROM usmd120c INTO lv_crequest_type WHERE usmd_crequest = iv_cr_number. "#EC CI_SUBRC 100 ENDIF. 101 SELECT * FROM tvarvc INTO TABLE @DATA(lt_crtype) WHERE name = 'ZMDG_GTS_ALLOWED_CR'. 102 IF sy-subrc = 0 AND line_exists( lt_crtype[ low = lv_crequest_type ] ). 103* IF lv_crequest_type = 'ZSUPL2P1' OR lv_crequest_type = 'ZSUPL4P2' . 104* IF 1 = 2. 105 cv_new_step = '35'. 106 cv_new_cr_status = 'T1'. 107 REFRESH ct_non_user_agent_group. 108 ls_non_user-agent_group = '001'. 109 ls_non_user-process_pattern = '02'. 110 ls_non_user-service_name = 'ZMDG_GTS_CALL'. 111 APPEND ls_non_user TO ct_non_user_agent_group. 112 CLEAR: ls_non_user. 113* ENDIF. 114 ENDIF. 115 ENDIF. 116* EOC by TE581834 for GTS call before activation step 117* IF lv_change_flag IS INITIAL. 118* cv_new_step = '99'. 119* cv_new_cr_status = '05'. 120* REFRESH ct_non_user_agent_group.

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

Related questions and keywords

Alternative questions

  • How does a dynamic agent BAdI route SAP MDG supplier approvals at runtime?
  • How do I fill CT_USER_AGENT_GROUP and CT_NON_USER_AGENT_GROUP in MDG dynamic agent selection?
  • How can I trigger a GTS technical step before supplier activation in SAP MDG workflow?

Possible questions

  • What does IF_USMD_SSW_DYNAMIC_AGT_SELECT do?
  • How do I read the change request object list in an MDG dynamic agent class?
  • How do I set CV_NEW_STEP and CV_NEW_CR_STATUS in a supplier workflow BAdI?
  • How do I add a non-user agent for a technical MDG step?
  • How do I adapt this pattern for another MDG scenario or CR type?

Keywords

SAP MDGdynamic agentIF_USMD_SSW_DYNAMIC_AGT_SELECTCT_USER_AGENT_GROUPCT_NON_USER_AGENT_GROUPCV_NEW_STEPCV_NEW_CR_STATUSZMDG_SUP_DYN_AGENTUSMD_CREQUESTUSMD120CGTSsupplier workflow