SAP MDG · UTILITIES

How do I build workflow diagnostics for an SAP MDG Change Request?

Use `USMD2400` to get the top workflow item for the Change Request, fall back to `CL_USMD_WF_SERVICE=>get_cr_top_wf` if needed, then read dialog work items from `SWWWIHEAD` and assignees from `SWWUSERWI`. Enrich the assigned users with emails from `USR21` and `ADR6`, and derive a workflow error message when the CR has no workflow, is in error, or has no READY work items.

Use `USMD2400` to get the top workflow item for the Change Request, fall back to `CL_USMD_WF_SERVICE=>get_cr_top_wf` if needed, then read dialog work items from `SWWWIHEAD` and assignees from `SWWUSERWI`. Enrich the assigned users with emails from `USR21` and `ADR6`, and derive a workflow error message when the CR has no workflow, is in error, or has no READY work items.

This workflow diagnostics pattern for an SAP MDG Change Request reads the top work item, current dialog work items, assigned users, and email addresses, then derives a simple workflow error message for dashboard use. It uses `USMD2400`, `SWWWIHEAD`, `SWWUSERWI`, `USR21`, `ADR6`, and the fallback `CL_USMD_WF_SERVICE=>get_cr_top_wf` when the CR does not already carry a top work-item reference.

Process flow

  1. Read `TOP_WI_ID` from `USMD2400` for the Change Request.
  2. If missing, call `CL_USMD_WF_SERVICE=>get_cr_top_wf` with `ID_SELECTION_VARIANT = 0001`.
  3. Read the top work item header from `SWWWIHEAD`.
  4. Select child work items from `SWWWIHEAD` with `WI_TYPE = 'W'`.
  5. Collect work-item IDs and read assigned users from `SWWUSERWI`.
  6. Resolve each assigned user to email using `USR21` and `ADR6`.
  7. Populate the workflow detail output structure and derive an error message if needed.

Referenced tables

ObjectPurpose
USMD2400Stores the top work-item reference for the Change Request.
SWWWIHEADWorkflow item header data including status, text, and top work-item relationship.
SWWUSERWIAssigned users for workflow items.
USR21Maps SAP user names to personnel numbers.
ADR6Stores email addresses for personnel records.

ILLUSTRATIVE ABAP SAMPLE

ABAP sample for CR workflow diagnostics

Source-adapted implementation pattern from `04_Workflow_Diagnostics_For_Change_Request.abap`. Replace the custom DDIC types if your dashboard uses different output structures.

1CLASS zcl_cr_workflow_diagnostics DEFINITION PUBLIC FINAL CREATE PUBLIC. 2 PUBLIC SECTION. 3 CLASS-METHODS fetch_wf_details 4 IMPORTING iv_cr TYPE usmd_crequest 5 EXPORTING es_wf_details TYPE zmdg_s_cr_wf_details 6 ev_workflow_error TYPE text200. 7ENDCLASS. 8 9CLASS zcl_cr_workflow_diagnostics IMPLEMENTATION. 10 METHOD fetch_wf_details. 11 DATA: lt_wi_ids TYPE TABLE OF sww_wiid. 12 13 SELECT SINGLE top_wi_id INTO @DATA(lv_wi_top) 14 FROM usmd2400 15 WHERE usmd_crequest = @iv_cr. 16 17 IF sy-subrc = 0. 18 SELECT SINGLE * INTO @DATA(ls_top_wi) 19 FROM swwwihead WHERE wi_id = @lv_wi_top. 20 ELSE. 21 CALL METHOD cl_usmd_wf_service=>get_cr_top_wf 22 EXPORTING id_crequest = iv_cr id_selection_variant = 0001 23 IMPORTING et_workflow = DATA(lt_wf_top). 24 READ TABLE lt_wf_top INTO DATA(ls_wf_row) INDEX 1. 25 IF sy-subrc = 0. 26 lv_wi_top = ls_wf_row-wi_id. 27 SELECT SINGLE * INTO @ls_top_wi FROM swwwihead WHERE wi_id = @lv_wi_top. 28 ENDIF. 29 ENDIF. 30 31 IF ls_top_wi IS NOT INITIAL. 32 SELECT * FROM swwwihead INTO TABLE @DATA(lt_items) 33 WHERE top_wi_id = @ls_top_wi-wi_id 34 AND wi_type = 'W'. 35 ENDIF. 36 37 LOOP AT lt_items INTO DATA(ls_item). 38 APPEND ls_item-wi_id TO lt_wi_ids. 39 ENDLOOP. 40 41 SELECT * FROM swwuserwi INTO TABLE @DATA(lt_userwi) 42 FOR ALL ENTRIES IN @lt_wi_ids 43 WHERE wi_id = @lt_wi_ids-table_line. 44 45 DATA: lt_wi TYPE zmdg_t_cr_wf_wi, 46 lt_users TYPE zmdg_t_cr_wf_users, 47 lt_users_all TYPE zmdg_t_cr_wf_users. 48 49 LOOP AT lt_items INTO ls_item. 50 DATA(ls_wi) = VALUE zmdg_s_cr_wf_wi( 51 workitem_id = ls_item-wi_id 52 status = ls_item-wi_stat ). 53 54 CLEAR lt_users. 55 LOOP AT lt_userwi INTO DATA(ls_userwi) WHERE wi_id = ls_item-wi_id. 56 DATA(ls_users) = VALUE zmdg_s_cr_wf_users( username = ls_userwi-user_id ). 57 58 SELECT SINGLE persnumber INTO @DATA(lv_persnumber) 59 FROM usr21 WHERE bname = @ls_userwi-user_id. 60 IF sy-subrc = 0. 61 SELECT SINGLE smtp_addr INTO @ls_users-email 62 FROM adr6 WHERE persnumber = @lv_persnumber. 63 ENDIF. 64 IF ls_users-email IS INITIAL. 65 ls_users-email = 'Not found'. 66 ENDIF. 67 68 APPEND ls_users TO lt_users. 69 APPEND ls_users TO lt_users_all. 70 ENDLOOP. 71 72 SELECT SINGLE wi_text INTO @ls_wi-wi_text 73 FROM swwwihead WHERE wi_id = @ls_wi-workitem_id. 74 75 ls_wi-users = lt_users. 76 APPEND ls_wi TO lt_wi. 77 ENDLOOP. 78 79 es_wf_details-top_workitem = ls_top_wi-wi_id. 80 es_wf_details-wf_status = ls_top_wi-wi_stat. 81 es_wf_details-workitems = lt_wi. 82 83 IF ls_top_wi-wi_id IS INITIAL. 84 ev_workflow_error = 'Workflow not triggered.'. 85 ELSEIF ls_top_wi-wi_stat = 'ERROR'. 86 ev_workflow_error = 'Workflow status in Error.'. 87 ELSEIF ls_top_wi-wi_stat <> 'COMPLETED' AND lt_users_all IS INITIAL. 88 ev_workflow_error = 'No user READY workitems found for Change Request'. 89 ENDIF. 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 read top work item, child work items, assigned users, and workflow error status for a CR?
  • Which tables and APIs are used for MDG workflow diagnostics?
  • How do I show workflow health information for a Change Request in a dashboard?

Possible questions

  • How do I detect whether a CR workflow was triggered?
  • How do I get the top workflow item for a Change Request?
  • How do I list current dialog work items for a CR?
  • How do I derive assigned users and email addresses from workflow work items?
  • How do I synthesize a workflow error message for a Change Request?

Keywords

SAP MDGChange Requestworkflow diagnosticsUSMD2400SWWWIHEADSWWUSERWIUSR21ADR6CL_USMD_WF_SERVICEtop workitemdialog workitememail address