SAP MDG · UTILITIES

How do I implement a safe SAP MDG change request cancellation method that rolls back the CR, completes workflow items, and writes a cancellation note?

Implement the cancellation in three parts: rollback the change request with `CL_USMD_WF_BO_SERVICE->ROLLBACK_CREQUEST`, complete any READY workflow items, and write a note to `USMD1210` using `BUILD_NOTE` + `ADD_CREQUEST_NOTE`. In the shown pattern, the code also reinitializes the MDG app context and runs an extra unblock check only when the CR type is `ZSUPBKD`.

Implement the cancellation in three parts: rollback the change request with `CL_USMD_WF_BO_SERVICE->ROLLBACK_CREQUEST`, complete any READY workflow items, and write a note to `USMD1210` using `BUILD_NOTE` + `ADD_CREQUEST_NOTE`. In the shown pattern, the code also reinitializes the MDG app context and runs an extra unblock check only when the CR type is `ZSUPBKD`.

A robust SAP MDG cancellation method should not only roll back the change request, but also clean up workflow items and persist an audit note. The documented pattern first calls `ROLLBACK_CREQUEST`, checks for errors, completes pending workitems, and then writes a formatted note built from the user action, reason code, and additional comment.

Process flow

  1. Instantiate `CL_USMD_WF_BO_SERVICE`.
  2. Call `ROLLBACK_CREQUEST` for the given CR.
  3. Check `USMD_T_MESSAGE` for error messages.
  4. If no error exists, call `ZCL_MDG_CR_PROCESS_UTIL=>COMPLETE_WORKITEM`.
  5. Create a success message in `LT_MESSAGE`.
  6. Build the cancellation note using `BUILD_NOTE` with user, reason code, and additional comment.
  7. Persist the note with `ADD_CREQUEST_NOTE` into `USMD1210`.
  8. Discard and reinitialize the app context for model `BP`.

MDG context initialization via `CL_USMD_APP_CONTEXT=>DISCARD_CONTEXT` and `CL_USMD_APP_CONTEXT=>INIT_CONTEXT`

Reset the MDG runtime context before evaluating the CR type after cancellation.

Referenced tables

ObjectPurpose
USMD1210Change request note timeline table where the cancellation note is inserted.
USMD120CChange request header/master data used by the broader MDG process pattern.
ZMDG_RECALL_REASCustom reason-text table read by `BUILD_NOTE` to compose the audit note.
USMD2301Workflow action customizing referenced by the reusable CR process utility.
SWW_WI2OBJWorkflow object-to-workitem mapping used by the broader workflow cleanup pattern.
SWWWIHEADWorkflow header table used by the broader workflow cleanup pattern.

ILLUSTRATIVE ABAP SAMPLE

SAP MDG CR cancellation method pattern

This sample is source-supported and follows the documented flow: rollback, complete workflow items, add note, and run the ZSUPBKD-specific unblock check.

1METHOD cancel_cr. 2 DATA: 3 ls_message TYPE usmd_s_message, 4 lt_message TYPE usmd_t_message, 5 lv_note TYPE usmd_note, 6 lv_action TYPE usmd_crequest_action, 7 lo_cr_service TYPE REF TO cl_usmd_wf_bo_service, 8 lo_context TYPE REF TO if_usmd_app_context, 9 lt_context_tab TYPE usmd_t_generic_context. 10 11 CREATE OBJECT lo_cr_service. 12 13 lo_cr_service->rollback_crequest( 14 EXPORTING 15 id_crequest = iv_cr 16 IMPORTING 17 et_message = lt_message ). 18 19 READ TABLE lt_message WITH KEY msgty = 'E' TRANSPORTING NO FIELDS. 20 IF sy-subrc <> 0. 21 zcl_mdg_cr_process_util=>complete_workitem( 22 EXPORTING 23 iv_cr = iv_cr ). 24 25 CLEAR lt_message. 26 ls_message-msgid = 'ZMDG'. 27 ls_message-msgno = 033. 28 ls_message-msgty = 'S'. 29 APPEND ls_message TO lt_message. 30 ENDIF. 31 32 READ TABLE lt_message WITH KEY msgty = 'S' TRANSPORTING NO FIELDS. 33 IF sy-subrc = 0. 34 build_note( 35 EXPORTING 36 iv_action = |Cancel by user: { sy-uname }| 37 iv_reason_code = iv_reason_code 38 iv_additional = iv_additional 39 IMPORTING 40 ev_note = lv_note ). 41 42 add_crequest_note( 43 iv_crequest_id = iv_cr 44 iv_note = lv_note ). 45 46 cl_usmd_app_context=>discard_context( ). 47 cl_usmd_app_context=>init_context( 48 EXPORTING 49 iv_model = 'BP' 50 iv_crequest_id = iv_cr ). 51 52 lo_context = cl_usmd_app_context=>get_context( ). 53 CHECK lo_context IS BOUND. 54 55 lo_context->get_attributes( 56 IMPORTING 57 ev_crequest_type = DATA(lv_crequest_type) ). 58 59 IF lv_crequest_type = 'ZSUPBKD'. 60 zcl_mdg_supplier_blk_unblk=>unblock_final_check( 61 EXPORTING 62 iv_cr_number = iv_cr 63 iv_service_name = 'ZMDG_ZSUPBKD_WITHDRAW_REP' 64 IMPORTING 65 ev_action = lv_action 66 et_message = lt_message 67 CHANGING 68 ct_context_tab = lt_context_tab ). 69 ENDIF. 70 ENDIF. 71 72 et_message = lt_message. 73ENDMETHOD.

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

Related questions and keywords

Alternative questions

  • How do I cancel an MDG change request programmatically with note logging?
  • How can I roll back an MDG CR and complete the pending workitems?
  • How do I add a cancellation audit note to USMD1210 in SAP MDG?

Possible questions

  • How do I cancel an MDG change request programmatically with note logging?
  • How can I roll back an MDG CR and complete the pending workitems?
  • How do I add a cancellation audit note to USMD1210 in SAP MDG?
  • How do I handle the ZSUPBKD-specific unblock check after CR cancellation?
  • Which MDG tables are updated when a CR is cancelled?

Keywords

SAP MDGABAPchange requestcancel CRrollback_crequestCL_USMD_WF_BO_SERVICEUSMD1210USMD120CCL_USMD_APP_CONTEXTZSUPBKDcomplete_workitemaudit note