Controlling SAP Workflow Termination
Controlling SAP Workflow Termination
Controlling Workflow Termination
In this note, I propose to look at a few ways to terminate a workflow. By "termination," I mean changing the status of the workflow. Specifically, I’ll show how to change the status of a running workflow based on a certain condition, as well as how to cancel it using a function module. Let’s go through these options.
Option 1: Terminate Workflow Based on a Condition
When designing your workflow using transaction SWDD, you may encounter a situation where you need to cancel or terminate the workflow based on some condition. By “condition,” I mean something like tracking the value of a workflow container element and using that to decide whether or not the workflow should be canceled or completed.
To demonstrate this approach, I’ll create a container element in my demo workflow called CANCEL_WF
.

To monitor the value of this element, you need to add a Condition step to the workflow.

What was done?
A condition was added to the workflow to evaluate the value of a container element. Next, we need to add a workflow termination step based on the value of CANCEL_WF
. In my case, if the value is "X"
, I will cancel the workflow; otherwise, it will continue. Add a Process Control step to the workflow.

Note the available workflow control functions when adding a Process Control step.

You can find help for each of these options by pressing F1.

In my example, the workflow status will be set to "Cancelled"
. Here’s a test run (apologies for the long GIF):

The workflow ends with the status "Cancelled". Now, I change the value of the CANCEL_WF
container element and run the test again (this time the previously added condition should not be triggered).

As expected.
Option 2: Terminate Workflow via Function Module SWP_WORKFLOW_ITEM_CANCEL
The second option is a bit simpler than the first. It’s worth considering, for example, if you want to cancel a running workflow from an ABAP program. Use the function module SWP_WORKFLOW_ITEM_CANCEL
, passing in the WI_ID
parameter, which takes the ID of the running workflow.

As a result of running this function module, the workflow status will change to CANCELLED.
