---
title: "转 Capture Rejection Reason Text from User Decision in Workflow "
author: "evangxli"
date: "2013-08-13T13:41:08Z"
tags: []
categories: ["行业应用"]
slug: "capture-rejection-reason-text-from-user-decision-in-workflow"
draft: false
lastmod: "2013-08-13T13:42:10Z"
id: 1917162
url: "https://sapabap.iteye.com/blog/1917162"
---

## Capture Rejection Reason Text from User Decision in Workflow

By Anirban Bhattacharjee, KPIT Cummins and Infosystems from [Link](http://www.saptechnical.com/)

**Purpose:** The purpose of this document is to capture the rejection reason text from the user decision step in workflow.

**Business Scenario:** When a user decision with the APPROVE and REJECT options are sent to the approver, there always comes a business need to allow the user to enter a “Rejection Reason” text, when the approver does a rejection. In the older SAP Releases, the standard User Decision step did not have a process to capture the rejection reason. The latest release of SAP includes this feature.

In this document we will see how to use this feature and capture the rejection reason text and also pass it to an e-mail sending step. This e-mail we can send to the original requestor so that he gets to know the cause of the rejection and resubmit for approval after the necessary corrections.

**Process:** This demo creation will involve the following steps

·         Create a user decision step with APPROVE and REJECT options and model the Rejection Reason only for the REJECT Branch.

·         Capture the rejection reason text and pass to an e-mail sending step via a container.

**Pre-requisites:** There are a few pre-requisites before doing this demo.

·         You should know how to build a basic workflow with the send e-mail step and user decision step. (SAP Technical.Com already has these tutorials)

·         SCOT and SAP Connect must be configured for e-mail sending.

·         All other workflow configurations via SWU3 are already done.

·         You know how to create methods in a custom BOR and call in workflows. (These will not be covered in details)

***Create Custom Workflow and Method to read the REJECTION Reason for Demo***

(Please read the tutorials on creation of Custom BOR/Method and Custom Workflow with user decisions and e-mail sending steps in SAP Technical.Com to get the details)

We create the user decision step and mark the two branches APPROVE and REJECTED as shown

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Index.1.jpg)

Notice that in the latest SAP version, we have an option to configure the Rejection / Approval reasons.

You can use this for any reason you want as per the branch you have created.

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Index.2.jpg)

We can mark the Reason as Mandatory or Required.

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Index.3.jpg)

**Mandatory:** This means, that the Reason has to be mandatorily entered when the corresponding action is performed, else the user decision work item cannot be completed.

**Required:** This means, that entering the Reason is optional. The pop-up to enter the reason will appear, but it is not needed to enter anything to complete the work item.

Here we will mark this Reason as MANDATORY for our REJECT Branch as shown

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Index.4.jpg)

The step is saved. When the user enters the Reason, it will get appended into the **\_Attach\_Objects** standard container of the workflow.

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Index.5.jpg)

This multiline element points to the **SOFM** Business Object.

We will now write a method to read this attachment and transfer to a text string.

This method will be an instance independent method. This means, it can be called without instantiating the BOR.

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Index.6.jpg)

The parameters for this method are shown below

**![](http://www.saptechnical.com/Tutorials/Workflow/UD/Index.7.jpg)**

The details of the parameters are

**Parameter WORKITEMID:**

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page2.8.jpg)

**Parameter REASON\_TXT:**

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page2.9.jpg)

We will be passing the work item ID of the workflow and this method will read the container **\_Attach\_Objects** and pass the Rejection Text to variable **REASON\_TXT**.

The code that you will write in the method is given below: (You can write your own code to read and process the SOFM Attachment Object as per your need)

begin\_method read\_rejection\_reason changing container.

DATA: reason\_txt TYPE swcont-value,  
      reason TYPE swc\_object OCCURS 0,  
      object\_content LIKE solisti1 OCCURS 0,  
      workitemid LIKE swr\_struct-workitemid,  
      subcontainer\_all\_objects LIKE TABLE OF swr\_cont,  
      lv\_wa\_reason LIKE LINE OF subcontainer\_all\_objects,  
      lv\_no\_att LIKE  sy-index,  
      document\_id LIKE sofolenti1-doc\_id,  
      return\_code LIKE  sy-subrc,  
      ifs\_xml\_container TYPE  xstring,  
      ifs\_xml\_container\_schema TYPE  xstring,  
      simple\_container LIKE TABLE OF swr\_cont,  
      message\_lines LIKE TABLE OF swr\_messag,  
      message\_struct LIKE TABLE OF swr\_mstruc,  
      subcontainer\_bor\_objects LIKE TABLE OF swr\_cont.

swc\_get\_table container 'REASON' reason.  
swc\_get\_element container 'WORKITEMID' workitemid.

* Read the work item container from the work item ID  
CALL FUNCTION 'SAP\_WAPI\_READ\_CONTAINER'  
  EXPORTING  
    workitem\_id              = workitemid  
    language                 = sy-langu  
    user                     = sy-uname  
  IMPORTING  
    return\_code              = return\_code  
    ifs\_xml\_container        = ifs\_xml\_container  
    ifs\_xml\_container\_schema = ifs\_xml\_container\_schema  
  TABLES  
    simple\_container         = simple\_container  
    message\_lines            = message\_lines  
    message\_struct           = message\_struct  
    subcontainer\_bor\_objects = subcontainer\_bor\_objects  
    subcontainer\_all\_objects = subcontainer\_all\_objects.

* Initialize  
lv\_no\_att = 0.

* Read the \_ATTACH\_OBJECTS element  
LOOP AT subcontainer\_all\_objects INTO lv\_wa\_reason  
                                 WHERE element = '\_ATTACH\_OBJECTS'.  
  lv\_no\_att = lv\_no\_att + 1.  
  document\_id = lv\_wa\_reason-value.

ENDLOOP.

* Read the SOFM Document  
CALL FUNCTION 'SO\_DOCUMENT\_READ\_API1'  
  EXPORTING  
    document\_id    = document\_id  
  TABLES  
    object\_content = object\_content.

* Pass the text to the exporting parameter  
IF sy-subrc = 0.  
  READ TABLE object\_content INTO reason\_txt INDEX 1.  
  SHIFT reason\_txt BY 5 PLACES LEFT.  
  swc\_set\_element container 'REASON\_TXT' reason\_txt.  
ENDIF.

end\_method.

Note that the method we created, **READ\_REJECTION\_REASON** can be executed even without instantiating the BOR

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page2.10.jpg)

The above method will be called in a standard task and called in the REJECT branch of the user decision step.

The standard task will look like as shown below

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page3.11.jpg)

The binding in this standard task

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page3.12.jpg)

The binding in the workflow to this task is shown as below

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page3.13.jpg)

**Predecessor work item will contain the Work Item ID of the User Decision Step.**

**The user decision step is just the previous step to this background step in this workflow template.**

The workflow will look like as shown below after adding the above step in the REJECT branch of the User Decision

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page3.14.jpg)

Now we will create an e-mail step after this “Read Rejection Reason Text”. Here we will pass our text and send as an e-mail.

For simplicity of the demo, I will be hard-coding a dummy e-mail ID to the send e-mail step.

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page3.15.jpg)

After this process, the complete workflow template will look as shown below

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page3.16.jpg)

We have not modeled anything for APPROVED branch, since we are show casing only the Rejection Reason.

You can model the Approve or any other branch as per your business need.

We are now ready to test the workflow.

We will run transaction **SWUS** to test the workflow

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page4.17.jpg)

We run the user decision from business workplace **SBWP**

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page4.18.jpg)

Now select REJECT to process rejection. Normally the work item would get completed here, but the system will generate a POP-UP to prompt for the Reason.

This pop-up will appear due to our configuration. We enter the REJECTION Reason text and press OK

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page4.19.jpg)

(Please note, if you cancel this POP-UP, the work item will still remain in your inbox and not get completed. This is because we marked the Reason as MANDATORY)

Looking at the workflow log, we can see that the element **\_ATTACH\_OBJECTS (Attachments)** contains the SOFM entry

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page4.20.jpg)

Now looking at the e-mail step in the log, we will check the task description to see if our text is captured

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page4.21.jpg)

You can see the Rejection Reason is captured. We can see this in the container also

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page4.22.jpg)

Now running the SOST transaction to see if the same appears in the e-mail body as well

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page4.23.jpg)

![](http://www.saptechnical.com/Tutorials/Workflow/UD/Page4.24.jpg)

So we have successfully captured the REJECTION REASON TEXT and displayed it in the e-mail body.

You can use this functionality in multitude of other ways as per your business need in your project.