SAP MDG · UTILITIES
How can SAP MDG determine the previous workflow step and action for a change request?
The method reads the top workflow for the change request, fetches its work items, and inspects the workflow container of the previous work item to return APPSTEP and ACTION_RESULT. It also counts approver levels until ACTION_RESULT = '07' and stores that count in memory ID LEVEL.
The method reads the top workflow for the change request, fetches its work items, and inspects the workflow container of the previous work item to return APPSTEP and ACTION_RESULT. It also counts approver levels until ACTION_RESULT = '07' and stores that count in memory ID LEVEL.
The method first resolves the top workflow for the change request via CL_USMD_WF_SERVICE=>GET_CR_TOP_WF, then gets the work items with CL_USMD_WF_SERVICE=>GET_WI_BY_TOPWI. It sorts the work items, selects the relevant previous item based on memory ID LAST_APPR, and reads the workflow container with SAP_WAPI_READ_CONTAINER to derive APPSTEP and ACTION_RESULT.
Process flow
- Call CL_USMD_WF_SERVICE=>GET_CR_TOP_WF for the change request ID.
- Take the first top workflow work item ID and pass it to CL_USMD_WF_SERVICE=>GET_WI_BY_TOPWI.
- Sort the returned work items by WI_ID ascending.
- Read memory ID LAST_APPR to decide whether to use the last or previous line.
- Read the selected work item container using SAP_WAPI_READ_CONTAINER.
- Extract APPSTEP into EV_CR_STEP and ACTION_RESULT into EV_STEP_ACTION.
- Loop through all work items, count approver levels, and stop when ACTION_RESULT = '07'.
- Export the approver level to memory ID LEVEL.
Referenced tables
| Object | Purpose |
|---|---|
SWWWIHEAD | Workflow work item header data used after resolving the top workflow. |
SWR_CONT | Workflow container table read by SAP_WAPI_READ_CONTAINER to extract APPSTEP and ACTION_RESULT. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1METHOD get_cr_previous_step.
2 DATA: lt_top_wi TYPE usmd_t_wi,
3 lt_wis TYPE STANDARD TABLE OF swwwihead,
4 ls_wi TYPE swwwihead,
5 lt_cont TYPE STANDARD TABLE OF swr_cont,
6 ls_cont TYPE swr_cont,
7 lv_gts TYPE boolean,
8 lv_approver_level TYPE n.
9
10 cl_usmd_wf_service=>get_cr_top_wf(
11 EXPORTING
12 id_crequest = iv_cr_id " Change Request
13 IMPORTING
14 et_workflow = DATA(lt_top_wf)
15 ).
16 IF lt_top_wf IS NOT INITIAL.
17 APPEND lt_top_wf[ 1 ]-wi_id TO lt_top_wi.
18 ENDIF.
19 cl_usmd_wf_service=>get_wi_by_topwi(
20 EXPORTING
21 it_topwi = lt_top_wi " Workitems
22 RECEIVING
23 rt_workitem = lt_wis " Workflow: Tabelle mit Workitems
24 ).
25 SORT lt_wis BY wi_id ASCENDING.
26 DATA(lv_line) = lines( lt_wis ).
27 IMPORT lv_gts TO lv_gts FROM MEMORY ID 'LAST_APPR'.
28 IF lv_gts = abap_false.
29 lv_line -= 1.
30 ENDIF.
31 TRY.
32 READ TABLE lt_wis INTO ls_wi INDEX lv_line.
33 IF sy-subrc = 0.
34 CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'
35 EXPORTING
36 workitem_id = ls_wi-wi_id
37 TABLES
38 simple_container = lt_cont.
39 READ TABLE lt_cont INTO ls_cont WITH KEY element = 'APPSTEP'.
40 IF sy-subrc = 0.
41 ev_cr_step = ls_cont-value.
42 ENDIF.
43 CLEAR: ls_cont.
44 READ TABLE lt_cont INTO ls_cont WITH KEY element = 'ACTION_RESULT'.
45 IF sy-subrc = 0.
46 ev_step_action = ls_cont-value.
47 ENDIF.
48 LOOP AT lt_wis INTO ls_wi.
49 CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'
50 EXPORTING
51 workitem_id = ls_wi-wi_id
52 TABLES
53 simple_container = lt_cont.
54 CLEAR: ls_cont.
55 READ TABLE lt_cont INTO ls_cont WITH KEY element = 'ACTION_RESULT'.
56 IF sy-subrc = 0.
57 lv_approver_level += 1.
58 IF ls_cont-value = '07'.
59 EXIT.
60 ENDIF.
61 ENDIF.
62 ENDLOOP.
63 EXPORT lv_approver_level FROM lv_approver_level TO MEMORY ID 'LEVEL'.
64 ENDIF.
65 CATCH cx_root.
66 ENDTRY.
67ENDMETHOD.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How do I read the previous approval step from an MDG change request workflow?
- Which classes and workflow containers are used to get the last MDG step and action?
- How can I calculate the previous approver level in MDG workflow?
Possible questions
- How can I read the previous workflow step for an MDG change request?
- How do I get the last action result from an MDG workflow work item?
- How does the method use memory IDs LAST_APPR and LEVEL?
- What SAP APIs are used to inspect the workflow container for a change request?
- Can I adapt this logic for another MDG object type?