转 Process a User Decision Programmatically at Background

Process a User Decision Programmatically at Background

By Anirban Bhattacharjee, KPIT Cummins and Infosystems from Link

Purpose: This document will show how to process a branch in a User Decision step in workflow via an ABAP Program running at the background. The desired branch can be executed programmatically without the approver having to process the work item from the SAP Inbox (SBWP or UWL).

Business Scenario: There are some business requirements where a user decision step needs to be processed at the background. For example, if we need to process auto rejection when a user decision is not executed within a stipulated time, we can employ this technique. We can also create an ABAP Program by which an approver can also process mass approval / rejection of all user decision work items. So this technique can come pretty handy on different business requirements.

Process: The process to set this up is pretty simple.

We simply need to call a function module and pass the work item ID of the User Decision along with the decision branch.

We will discuss in details on how to achieve this functionality.

For our demo, I will consider two user decision work items that are sitting in a user’s business workplace.

We will process APPROVE for one and REJECT branch for the other without executing them from business workplace (SBWP) or UWL in portal.

The two work items in the business work place of the user are shown below

We now look each the user decision step in workflow

Thus the APPROVE will correspond to branch 0001 and REJECT will correspond to 0002. If the step had other decision options, they would get numbered as 0003, 0004 and so on.

Now to process the user decision via an ABAP program without executing the work item from SBWP or Portal UWL we need to run the following function module

SAP_WAPI_DECISION_COMPLETE

Let us see what importing data this function module needs

Here in the parameter WORKITEM_ID we will pass the work item ID of the User Decision Step.

For USER, the default is SY-UNAME. Hence if this function module is called in an ABAP Program and that program is executed at the background, it will pass the background system user ID.

The parameter DECISION_KEY decides which branch has to be processed in the User Decision Step. As explained before, we will pass 0001 for APPROVE and 0002 for REJECT.

This will differ from case-to-case and scenario-to-scenario.

Now fetching the work item IDs of the above two user decision work items from their workflow logs

Work Item ID is 2733503 (We will process APPROVE for this)

 

Work Item ID is 2733501 (We will process REJECT for this)

Running the function module with work item ID 2733503 (Process Decision Key 0001 for APPROVE)

Now we will look at the workflow graphical log to verify which branch was executed. In this case it should be APPROVE (0001)

Result Outcome is APPROVE

So the APPROVE branch was executed here.

Now will run the function module with the other work item ID 2733501 (Process Decision Key 0002 for REJECT)

Now we will look at the workflow graphical log to verify which branch was executed. In this case it should be REJECT (0002)

Result outcome is REJECT

So the REJECT branch was executed here.

Now we will check the business work place via SBWP. The work items should have been removed.

BEFORE

AFTER

We can thus call this function module SAP_WAPI_DECISION_COMPLETE in our ABAP Program and design it for so many different purposes.

We can also call the ABAP Program at the background and process work items accordingly.

Conclusion: We have thus successfully processed a user decision step programmatically without executing the work item from the business workplace.

猜你喜欢

转载自sapabap.iteye.com/blog/1917165