From the release of SAP® NW04 version, SAP® has introduced many new features among which exception handling is one.Exception handling is done in workflow using Blocks (TRY-CATCH mechanism). “Blocks” is one of the new features introduced from NW04 version.
This document details about the usage of Blocks and the approach to trigger and handle the exceptions.
Before that you can read : Create Simple SAP Workflow Tutorial
Pre-requisites
It is assumed that the reader of this article has some knowledge in SAP® workflow and has worked with the steps Mail, Process control earlier.
Overview of Blocks
- Blocks could be treated as folders combining a group of dependent work items. They are shown as folders in the workflow log.
- Each block would have start and end nodes.
- Blocks can be deadline monitored (only Latest End)
- Blocks can catch exceptions
Following are the screenshots representing how a “Block” appears in the workflow definition and in the workflow log:
Fig: Appearance of “Block” in the Workflow definition.
Fig: Appearance of “Block” in the Workflow log
A “Block” is completed only if the dependent work items are complete or in the final state. If a “Block” is cancelled, all its dependent work items are cancelled.
Each “Block” can have its own container elements. All the parent container elements are visible within the “Block”.
Defining a Block
- Start a new workflow definition using the transaction SWDD
- Double-click on the “Undefined step” and select “Block”.
- Enter the step name and leave the block type as “Standard”. Press Enter. The workflow definition would be appearing as follows:
All the dependent steps could be defined with in the Block start and Block end.
Blocks can handle exceptions. If an exception is caught, everything inside the block is cancelled. If exception is not caught, process is set to an ERROR state (This could be compared to TRY-CATCH in ABAPTM programs. If the exception is not caught, program results in dump)
- Create a new workflow and define a new step “Block” as mentioned earlier page.
- In the “Block” step, click on the tab “Exceptions” and make an entry of a new exception, for e.g., “Dummy_Excep”, which would be raised in the workflow definition.
- Activate the exception defined above, by clicking on the button left to the exception name
- Go back to the main screen. Two branches would be appearing between the block begin and block end, as shown below. Exception branch is taken whenever the exception, Dummy_Excep, is triggered.
- Exceptions are triggered using the step “Process Control”. Define a new step “Process Control” in the normal branch. Enter the step name and the outcome name. Select “Throw Exception” in the function. In the event name, select the exception name defined earlier (see the screenshot below).
- Uncheck “Step not in workflow log” if you would like to see this step in the workflow log.
- Define a mail step in the exception branch of the block (for testing purpose – to ensure that this exception branch is taken, when the exception is triggered). The execution flow of the exception handling is shown below: