SAP MDG · UTILITIES

How do I complete all READY workflow work items for an SAP MDG Change Request programmatically?

Use the CR number to resolve the MDG change request, map it to workflow instance IDs in SWW_WI2OBJ for object BUS2250, find READY items in SWWWIHEAD, and complete each item with SAP_WAPI_WORKITEM_COMPLETE.

Use the CR number to resolve the MDG change request, map it to workflow instance IDs in SWW_WI2OBJ for object BUS2250, find READY items in SWWWIHEAD, and complete each item with SAP_WAPI_WORKITEM_COMPLETE.

To complete pending MDG workflow items for a change request, first resolve the CR in USMD120C, then map it to the related BUS2250 workflow instance in SWW_WI2OBJ. After that, read the READY entries from SWWWIHEAD and complete each work item with SAP_WAPI_WORKITEM_COMPLETE.

Process flow

  1. Validate the CR number is not initial
  2. Read the CR from USMD120C
  3. Build the BUS2250 instance ID from the CR number
  4. Read workflow links from SWW_WI2OBJ
  5. Read READY items from SWWWIHEAD
  6. Call SAP_WAPI_WORKITEM_COMPLETE for each READY work item

Referenced tables

ObjectPurpose
USMD120CStores MDG change request header data used to validate and resolve the CR
SWW_WI2OBJMaps workflow work items to business object instances such as BUS2250
SWWWIHEADStores workflow item header data including work item status READY

ILLUSTRATIVE ABAP SAMPLE

ABAP implementation of COMPLETE_WORKITEM

Source-supported sample that resolves the CR, finds BUS2250 workflow items, filters READY items, and completes them with SAP_WAPI_WORKITEM_COMPLETE.

1METHOD complete_workitem. 2 TYPES: 3 BEGIN OF ty_cr, 4 usmd_crequest TYPE usmd120c-usmd_crequest, 5 usmd_creq_text TYPE usmd120c-usmd_creq_text, 6 END OF ty_cr, 7 BEGIN OF ty_wi2obj, 8 instid TYPE sww_wi2obj-instid, 9 top_wi_id TYPE sww_wi2obj-top_wi_id, 10 END OF ty_wi2obj, 11 BEGIN OF ty_wihead, 12 wi_id TYPE swwwihead-wi_id, 13 top_wi_id TYPE swwwihead-top_wi_id, 14 wi_cd TYPE swwwihead-wi_cd, 15 wi_ct TYPE swwwihead-wi_ct, 16 END OF ty_wihead. 17 18 DATA: 19 lt_cr_range TYPE RANGE OF usmd120c-usmd_crequest, 20 lt_instid_range TYPE RANGE OF sww_wi2obj-instid, 21 lt_topwi_range TYPE RANGE OF swwwihead-top_wi_id, 22 lt_cr TYPE STANDARD TABLE OF ty_cr WITH EMPTY KEY, 23 lt_wi2obj TYPE STANDARD TABLE OF ty_wi2obj WITH EMPTY KEY, 24 lt_ready_wi TYPE STANDARD TABLE OF ty_wihead WITH EMPTY KEY, 25 ls_cr_range LIKE LINE OF lt_cr_range, 26 ls_instid_range LIKE LINE OF lt_instid_range, 27 ls_topwi_range LIKE LINE OF lt_topwi_range. 28 29 IF iv_cr IS INITIAL. 30 RETURN. 31 ENDIF. 32 33 ls_cr_range-sign = 'I'. 34 ls_cr_range-option = 'EQ'. 35 ls_cr_range-low = iv_cr. 36 APPEND ls_cr_range TO lt_cr_range. 37 38 SELECT usmd_crequest, usmd_creq_text 39 FROM usmd120c 40 INTO CORRESPONDING FIELDS OF TABLE @lt_cr 41 WHERE usmd_crequest IN @lt_cr_range. 42 43 IF sy-subrc <> 0. 44 RETURN. 45 ENDIF. 46 47 LOOP AT lt_cr ASSIGNING FIELD-SYMBOL(<ls_cr>). 48 CLEAR ls_instid_range. 49 ls_instid_range-sign = 'I'. 50 ls_instid_range-option = 'EQ'. 51 ls_instid_range-low = <ls_cr>-usmd_crequest && '000000'. 52 APPEND ls_instid_range TO lt_instid_range. 53 ENDLOOP. 54 55 SELECT instid, top_wi_id 56 FROM sww_wi2obj 57 INTO CORRESPONDING FIELDS OF TABLE @lt_wi2obj 58 WHERE instid IN @lt_instid_range 59 AND typeid = 'BUS2250'. 60 61 IF sy-subrc <> 0 OR lt_wi2obj IS INITIAL. 62 RETURN. 63 ENDIF. 64 65 LOOP AT lt_wi2obj ASSIGNING FIELD-SYMBOL(<ls_wi2obj>). 66 CLEAR ls_topwi_range. 67 ls_topwi_range-sign = 'I'. 68 ls_topwi_range-option = 'EQ'. 69 ls_topwi_range-low = <ls_wi2obj>-top_wi_id. 70 APPEND ls_topwi_range TO lt_topwi_range. 71 ENDLOOP. 72 73 SELECT wi_id, top_wi_id, wi_cd, wi_ct 74 FROM swwwihead 75 INTO CORRESPONDING FIELDS OF TABLE @lt_ready_wi 76 WHERE top_wi_id IN @lt_topwi_range 77 AND wi_stat = 'READY'. 78 79 IF sy-subrc <> 0 OR lt_ready_wi IS INITIAL. 80 RETURN. 81 ENDIF. 82 83 LOOP AT lt_ready_wi ASSIGNING FIELD-SYMBOL(<ls_ready_wi>). 84 CALL FUNCTION 'SAP_WAPI_WORKITEM_COMPLETE' 85 EXPORTING 86 workitem_id = <ls_ready_wi>-wi_id 87 EXCEPTIONS 88 OTHERS = 1. 89 ENDLOOP. 90ENDMETHOD.

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

Related questions and keywords

Alternative questions

  • How can I finish pending MDG workflow items for a change request?
  • What ABAP logic completes READY work items for an MDG CR?
  • How do I clean up workflow items linked to BUS2250?

Possible questions

  • How do I complete all READY workflow work items for an SAP MDG Change Request programmatically?
  • How can I finish pending MDG workflow items for a change request?
  • What ABAP logic completes READY work items for an MDG CR?
  • How do I clean up workflow items linked to BUS2250?
  • Which tables are used to find workflow items for an MDG CR?
  • What is the ABAP sample for completing workflow items in MDG?

Keywords

SAP MDGChange RequestworkflowREADY work itemBUS2250SWW_WI2OBJSWWWIHEADUSMD120CSAP_WAPI_WORKITEM_COMPLETEABAP