SAP MDG · UTILITIES

How do I implement a reusable SAP MDG utility class for change request cancel, recall, workflow completion, and note handling in model BP?

Use a stateless public final class with CLASS-METHODS only: CANCEL_CR, COMPLETE_WORKITEM, RECALL_CR, ADD_CREQUEST_NOTE, and BUILD_NOTE. The documented pattern for model BP is to roll back the CR, complete READY workitems, validate workflow context and allowed recall action, and write audit notes into USMD1210 with SAP_WFRT as creator.

Use a stateless public final class with CLASS-METHODS only: CANCEL_CR, COMPLETE_WORKITEM, RECALL_CR, ADD_CREQUEST_NOTE, and BUILD_NOTE. The documented pattern for model BP is to roll back the CR, complete READY workitems, validate workflow context and allowed recall action, and write audit notes into USMD1210 with SAP_WFRT as creator.

ZCL_MDG_CR_PROCESS_UTIL is designed as a reusable stateless ABAP utility for SAP MDG change request processing in model BP. It provides CLASS-METHODS for canceling a CR, recalling it to the requestor, completing READY workflow items, and persisting audit notes in USMD1210. The documented pattern is to keep workflow actions and note creation together so UI or service callers can return a single message table to the user.

Process flow

  1. Create class ZCL_MDG_CR_PROCESS_UTIL as FINAL and CREATE PUBLIC.
  2. Define only CLASS-METHODS for CANCEL_CR, COMPLETE_WORKITEM, RECALL_CR, ADD_CREQUEST_NOTE, and BUILD_NOTE.
  3. Implement ADD_CREQUEST_NOTE with CL_USMD_CREQUEST_API and insert into USMD1210.
  4. Implement BUILD_NOTE by reading reason_text from ZMDG_RECALL_REAS.
  5. Implement COMPLETE_WORKITEM by resolving workflow items from SWW_WI2OBJ and SWWWIHEAD and completing READY items with SAP_WAPI_WORKITEM_COMPLETE.
  6. Implement RECALL_CR with workflow context, BAPI_USER_GET_DETAIL validation, USMD2301 action derivation, and note creation.
  7. Implement CANCEL_CR with CL_USMD_WF_BO_SERVICE->ROLLBACK_CREQUEST, work item completion, and post-cancel check for ZSUPBKD.
  8. Return USMD_T_MESSAGE to the caller for UI feedback.

Referenced tables

ObjectPurpose
USMD120CChange request to process/type context used by the utility when resolving CR information.
USMD1210CR note timeline table where ADD_CREQUEST_NOTE writes audit comments with SAP_WFRT as creator.
USMD2301Workflow step customizing used to determine the valid recall action.
SWW_WI2OBJWorkflow object-to-workitem mapping used by COMPLETE_WORKITEM.
SWWWIHEADWorkflow work item header/status source used to find READY items.
ZMDG_RECALL_REASCustom reason text table used by BUILD_NOTE.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example: Change Request Report.abap

Exact relevant implementation excerpt from the knowledge document set.

1*&---------------------------------------------------------------------* 2*& Report CHANGE_REQUEST_REPORT 3*&---------------------------------------------------------------------* 4*& Purpose: 5*& This report creates a flattened, non-modular view of the change 6*& request extraction logic from ZMDG_CHANGE_REQUEST_REPORT. 7*& 8*& What it does: 9*& - Reads change requests of type ZSUP* created in a time window 10*& - Resolves the BP technical key from USMD1213 11*& - Finds the dynamic generated staging table for BP data 12*& - Reads organizational and vendor-specific data dynamically 13*& - Combines header data and staging data into ZMDG_CHGREQ 14*& - Updates the target table with the generated results 15*& 16*& This file is intentionally flattened so the full flow can be studied 17*& without navigating includes or FORM modularization. 18*&---------------------------------------------------------------------* 19 20REPORT zmdg_change_request_report. 21 22"--------------------------------------------------------------------- 23" Global data declarations from the TOP include 24" These variables hold the selection window, technical keys, dynamic 25" table references, and the final output rows. 26"--------------------------------------------------------------------- 27DATA: gv_low TYPE timestamp, 28 gv_high TYPE timestamp, 29 gv_sid TYPE usmd_flg, 30 gt_techkey TYPE TABLE OF usmd_tech_key, 31 gs_techkey TYPE usmd_tech_key, 32 gt_techkey1 TYPE TABLE OF usmd_tech_key, 33 gt_usmd1210 TYPE STANDARD TABLE OF usmd1210, 34 gs_final TYPE zmdg_chgreq. 35 36" Range table for filtering change request types. 37DATA: gr_type TYPE RANGE OF usmd_crequest_type. 38 39" Helper structures for dynamic field handling. 40DATA: lt_key_fields_range TYPE RANGE OF name_komp, 41 lt_key_fields TYPE TABLE OF name_komp, 42 ls_key_data TYPE REF TO data, 43 go_data TYPE REF TO data. 44 45FIELD-SYMBOLS: <lfs_t_org_data> TYPE ANY TABLE, 46 <lfs_t_vengen> TYPE ANY TABLE. 47 48DATA: gr_data TYPE REF TO data. 49 50" Change request header data and intermediate technical-key mapping data. 51DATA: lt_usmd1213 TYPE TABLE OF usmd1213, 52 ls_usmd1213 TYPE usmd1213, 53 lt_usmd120c TYPE TABLE OF usmd120c, 54 ls_usmd120c TYPE usmd120c. 55 56" Final output buffer to be written to ZMDG_CHGREQ. 57DATA: gt_data TYPE TABLE OF zmdg_chgreq, 58 gs_data TYPE zmdg_chgreq. 59 60" Empty selection-screen include from the original program. 61" The original include exists only as a placeholder, so the flat version 62" keeps the same structure but does not add custom selection fields. 63 64"--------------------------------------------------------------------- 65" Main execution flow 66"--------------------------------------------------------------------- 67START-OF-SELECTION. 68 " Read and prepare the source data first. 69 PERFORM get_data. 70 71END-OF-SELECTION. 72 " After data extraction, build the final output rows and persist them. 73 PERFORM process_data. 74 75"--------------------------------------------------------------------- 76" FORM get_data 77" Purpose: 78" Collect all change requests and staging-table data needed to build 79" the flattened change request report. 80"--------------------------------------------------------------------- 81FORM get_data. 82 83 " Reset key runtime variables before the extraction starts. 84 CLEAR: gv_low, gv_high, gv_sid, gt_techkey. 85 86 " Only change request types that start with ZSUP are relevant. 87 gr_type = VALUE #( ( sign = 'I' option = 'CP' low = 'ZSUP*' ) ). 88 89 "--------------------------------------------------------------- 90 " Determine the extraction time window. 91 " If TVARVC contains a saved low timestamp, use it; otherwise use 92 " the current timestamp and subtract one month. 93 "--------------------------------------------------------------- 94 SELECT SINGLE * FROM tvarvc 95 INTO @DATA(ls_tvarvc) 96 WHERE name = 'ZMDG_REPORT2ONEDATA'. 97 IF sy-subrc = 0 AND ls_tvarvc-low IS NOT INITIAL. 98 gv_low = ls_tvarvc-low. 99 ELSE. 100 GET TIME STAMP FIELD DATA(lv_current_timestamp). 101 CONVERT TIME STAMP lv_current_timestamp TIME ZONE 'UTC' 102 INTO DATE DATA(lv_date) 103 TIME DATA(lv_time). 104 TRY. 105 cl_hrpad_date_computations=>add_months_to_date( 106 EXPORTING 107 start_date = lv_date 108 months = -1 109 RECEIVING 110 date = DATA(lv_past_date) 111 ). 112 CATCH cx_hrpa_violated_postcondition. 113 " Fallback if month subtraction hits a date postcondition. 114 lv_past_date = lv_date - 30. 115 ENDTRY. 116 CONVERT DATE lv_past_date TIME lv_time 117 INTO TIME STAMP DATA(lv_target_timestamp) TIME ZONE 'UTC'. 118 gv_low = lv_target_timestamp. 119 gv_high = lv_current_timestamp. 120 ENDIF.

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

Related questions and keywords

Alternative questions

  • How can I build a stateless ABAP helper class for MDG CR process actions?
  • What is the pattern for cancelling or recalling an MDG change request and writing audit notes?
  • How do I complete pending workflow items and append CR notes in SAP MDG?

Possible questions

  • What does ZCL_MDG_CR_PROCESS_UTIL do?
  • How does ADD_CREQUEST_NOTE work?
  • How is BUILD_NOTE used for MDG audit comments?
  • How do I complete READY workflow items for a change request?
  • How do I implement RECALL_CR logic in MDG?

Keywords

SAP MDGABAPchange requestworkflowrecallcancelUSMD1210USMD2301SWW_WI2OBJSWWWIHEADCL_USMD_CREQUEST_APICL_USMD_WF_BO_SERVICESAP_WAPI_WORKITEM_COMPLETEmodel BP