SAP MDG · UTILITIES
How do I restart a stuck SAP MDG Change Request workflow by cancelling the top work item and re-triggering BUS2250.CREATED?
Use `zcl_cr_workflow_restart=>restart_workflow( )` to cancel and delete the top work item for the Change Request, delete the CR-to-workflow mapping, and raise `BUS2250.CREATED` again with the original creator as event user.
Use `zcl_cr_workflow_restart=>restart_workflow( )` to cancel and delete the top work item for the Change Request, delete the CR-to-workflow mapping, and raise `BUS2250.CREATED` again with the original creator as event user.
The reusable restart pattern for an MDG Change Request is: find the CR’s top workflow item, cancel and delete it, remove the CR-to-workflow mapping, and then raise `BUS2250.CREATED` again so the workflow starts fresh. The supplied utility class `zcl_cr_workflow_restart` implements exactly that sequence using `USMD120C`, `USMD110C`, `cl_usmd_wf_crequest_mapper`, and the SAP workflow APIs.
Process flow
- Check that the Change Request number is available.
- Read the CR header data from `USMD120C` and `USMD110C`.
- Determine the top work item with `cl_usmd_wf_crequest_mapper=>get_top_wi_by_crequest_single( )`.
- Cancel the work item with `SAP_WAPI_ADM_WORKFLOW_CANCEL`.
- Delete the work item with `SAP_WAPI_WORKITEM_DELETE`.
- Delete the CR-to-workflow mapping with `cl_usmd_wf_crequest_mapper=>delete_mapping`.
- Build the object key as `<CR number> && '000000'`.
- Populate the event container with `CR_CREATOR` and `CR_WORKFLOW`.」「Trigger `SAP_WAPI_CREATE_EVENT` for `BUS2250` and event `CREATED`.
Referenced tables
| Object | Purpose |
|---|---|
USMD120C | Change Request header data, including creator and Change Request type. |
USMD110C | Change Request workflow type mapping, joined by Change Request type in the restart logic. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1*&---------------------------------------------------------------------*
2*& 07_CR_Workflow_Restart_By_Event
3*&---------------------------------------------------------------------*
4*& Reusable functionality:
5*& Restart CR workflow by cancelling top WI, deleting mapping,
6*& then raising BUS2250.CREATED event.
7*&---------------------------------------------------------------------*
8CLASS zcl_cr_workflow_restart DEFINITION PUBLIC FINAL CREATE PUBLIC.
9 PUBLIC SECTION.
10 CLASS-METHODS restart_workflow
11 IMPORTING iv_cr TYPE usmd_crequest.
12ENDCLASS.
13
14CLASS zcl_cr_workflow_restart IMPLEMENTATION.
15 METHOD restart_workflow.
16 CHECK iv_cr IS NOT INITIAL.
17
18 SELECT a~usmd_crequest, a~usmd_created_by, b~usmd_crequest_wf
19 INTO TABLE @DATA(lt_creq_tab)
20 FROM usmd120c AS a
21 INNER JOIN usmd110c AS b
22 ON b~usmd_creq_type = a~usmd_creq_type
23 WHERE a~usmd_crequest = @iv_cr.
24 CHECK lt_creq_tab IS NOT INITIAL.
25
26 DATA(ld_top_wi) = cl_usmd_wf_crequest_mapper=>get_top_wi_by_crequest_single( iv_cr ).
27
28 " 1) Cancel and delete existing top workflow item.
29 CALL FUNCTION 'SAP_WAPI_ADM_WORKFLOW_CANCEL'
30 EXPORTING
31 workitem_id = ld_top_wi
32 actual_agent = sy-uname
33 language = sy-langu
34 do_commit = 'X'.
35
36 CALL FUNCTION 'SAP_WAPI_WORKITEM_DELETE'
37 EXPORTING
38 workitem_id = ld_top_wi
39 actual_agent = sy-uname
40 language = sy-langu
41 check_final_state = 'X'
42 do_commit = 'X'
43 invoke_exit = 'X'.
44
45 " 2) Remove CR to workflow mapping.
46 CALL METHOD cl_usmd_wf_crequest_mapper=>delete_mapping
47 EXPORTING iv_crequest = iv_cr.
48
49 READ TABLE lt_creq_tab INTO DATA(ls_creq_det) INDEX 1.
50 CHECK sy-subrc = 0.
51
52 " 3) Raise CREATED event to start workflow again.
53 DATA(ld_obj_key) = iv_cr && '000000'.
54 DATA lt_cont TYPE TABLE OF swr_cont.
55
56 APPEND VALUE #( element = 'CR_CREATOR' value = ls_creq_det-usmd_created_by ) TO lt_cont.
57 APPEND VALUE #( element = 'CR_WORKFLOW' value = ls_creq_det-usmd_crequest_wf ) TO lt_cont.
58
59 CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
60 EXPORTING
61 object_type = 'BUS2250'
62 object_key = ld_obj_key
63 event = 'CREATED'
64 commit_work = 'X'
65 user = ls_creq_det-usmd_created_by
66 TABLES
67 input_container = lt_cont.
68 ENDMETHOD.
69ENDCLASS.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How can I restart an MDG Change Request workflow programmatically?
- How do I recover a stuck MDG workflow for a specific Change Request?
- How do I cancel the current workflow item, delete the mapping, and start the CR workflow again?
Possible questions
- How can approval information be read for an SAP MDG master-data object?
- Which API is used to search a G/L Account in data model 0G?
- How is a Change Request retrieved from an MDG entity key?
- Why is the Change Request the central object for approval-log retrieval?
- Which class retrieves workflow items for a Change Request?
- What is BOR object type BUS2250 used for?
- How is the workflow object key built?
- Which workflow item type represents a dialog task?
- Where are the approver user name and description stored?
- Which method reads the workflow container?
- What does the ACTION_RESULT container element represent?
- Which tables provide descriptions for Change Request actions?
- How can this approach be adapted to a different MDG data model or entity?
- Why must the return code be checked after workflow API calls?
- What is the purpose of GC_READMODE_ALL_INACT?