---
title: "转 Sending multiple attachment in user decision step of workflow"
author: "evangxli"
date: "2013-08-07T11:40:55Z"
tags: []
categories: ["行业应用"]
slug: "sending-multiple-attachment-in-user-decision-step-of-workflow"
draft: false
lastmod: "2013-08-07T11:40:55Z"
id: 1917156
url: "https://sapabap.iteye.com/blog/1917156"
---

#### Sending multiple attachment in user decision step of workflow

By Lokesh Tripathi, Infosys from [Link](http://www.saptechnical.com/)

# Business Requirement

This document describes how to send multiple attachments in the user decision step of the workflow.  
User can see multiple attachments and based on that take the necessary required decision.

This method would be helpful in business processes where user wants to introduce approval step before processing or accepting any finance report or other document.                                    

# Functional Specification

User will execute the custom report/transaction that will trigger the workflow (we can associate starting event also to this workflow).  
Workflow will send mail having multiple attachments to SAP Inbox as a user decision.  
Based on user decision rest logic would happen.

# Workflow Flow Diagram

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

 

**Technical Specification**

For adding attachments in the user decision steps method EVENT\_RAISED of interface IF\_SWF\_IFS\_WORKITEM\_EXIT needs to be implemented and it is used as a Function Exit in the user decision step.

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

Go to SE24, implement method EVENT\_RAISED of interface IF\_SWF\_IFS\_WORKITEM\_EXIT  
ZTEST\_WFATTACH is created for the same.

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

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

In this method code for inserting attachments needs to be implemented (Please use below code for the same)  
First check whether workflow container already have any attachments or not to avoid any duplications.

* Fetch the workflow work item Id  
CALL METHOD IM\_WORKITEM\_CONTEXT-&gt;GET\_WORKITEM\_ID  
    RECEIVING  
    RE\_WORKITEM = LV\_ID.

* Fetch Container  
CALL METHOD IM\_WORKITEM\_CONTEXT-&gt;GET\_WI\_CONTAINER  
    RECEIVING  
    RE\_CONTAINER = LV\_CONTAINER.  
* Read attachment to confirm that there is no duplication  
CLEAR LV\_OBJ\_RECORD.  
CALL METHOD LV\_CONTAINER-&gt;GET  
    EXPORTING  
      NAME  = '\_ATTACH\_OBJECTS'  
    IMPORTING  
      VALUE = LV\_ATTACH.  
**IF** **LV\_ATTACH IS INITIAL.**

If  there are no prior attachments then identify the folder id based on sy-user

CALL FUNCTION 'SO\_FOLDER\_ROOT\_ID\_GET'  
     EXPORTING  
       OWNER     = SY-UNAME  
       REGION    = 'B'  
     IMPORTING  
       FOLDER\_ID = LV\_FOLDER\_ID.

In this scenario we are converting spool output to PDF and attaching the same PDF in the user decision step    

Give spool number in  LV\_SPOOL field

CALL FUNCTION 'CONVERT\_ABAPSPOOLJOB\_2\_PDF'  
   EXPORTING  
        SRC\_SPOOLID              =  LV\_SPOOL  
        NO\_DIALOG                = ''  
        PDF\_DESTINATION          = 'X'  
   IMPORTING  
        PDF\_BYTECOUNT            = LA\_BYTE\_COUNT  
   TABLES  
        PDF                      = GT\_PDF  
   EXCEPTIONS  
        ERR\_NO\_ABAP\_SPOOLJOB     = 1  
        ERR\_NO\_SPOOLJOB          = 2  
        ERR\_NO\_PERMISSION        = 3  
        ERR\_CONV\_NOT\_POSSIBLE    = 4  
        ERR\_BAD\_DESTDEVICE       = 5  
        USER\_CANCELLED           = 6  
        ERR\_SPOOLERROR           = 7  
        ERR\_TEMSEERROR           = 8  
        ERR\_BTCJOB\_OPEN\_FAILED   = 9  
        ERR\_BTCJOB\_SUBMIT\_FAILED = 10  
        ERR\_BTCJOB\_CLOSE\_FAILED  = 11  
        OTHERS                   = 12.

LOOP AT GT\_PDF INTO LWA\_PDFLINE.  
  ASSIGN LWA\_PDFLINE TO &lt;L\_XLINE&gt; CASTING.  
  CONCATENATE PDF\_XSTRING &lt;L\_XLINE&gt;        
  INTO PDF\_XSTRING IN BYTE MODE.  
ENDLOOP.

* Create and set document  
IT\_SOLIX\_TAB1 = CL\_DOCUMENT\_BCS=&gt;XSTRING\_TO\_SOLIX (PDF\_XSTRING).

Creating First attachment

 LV\_DATA-OBJ\_NAME   = 'Test Sending Attachments'.  
 LV\_DATA-OBJ\_DESCR  = 'Attachment 1'.  
 LV\_DATA-OBJ\_LANGU  = SY-LANGU.  
 LV\_DATA-SENSITIVTY = 'P'.  
 LV\_DATA-DOC\_SIZE   = LA\_BYTE\_COUNT.

 CALL FUNCTION 'SO\_DOCUMENT\_INSERT\_API1'  
      EXPORTING  
          FOLDER\_ID                  = LV\_FOLDER\_ID  
          DOCUMENT\_DATA              = LV\_DATA  
          DOCUMENT\_TYPE              = 'PDF'  
      IMPORTING  
          DOCUMENT\_INFO              = WA\_DOCUMENT\_INFO  
      TABLES  
          CONTENTS\_HEX               = IT\_SOLIX\_TAB1  
      EXCEPTIONS  
          FOLDER\_NOT\_EXIST           = 1  
          DOCUMENT\_TYPE\_NOT\_EXIST    = 2  
          OPERATION\_NO\_AUTHORIZATION = 3  
          PARAMETER\_ERROR            = 4  
          X\_ERROR                    = 5  
          ENQUEUE\_ERROR              = 6  
          OTHERS                     = 7.  
* Populate object type and object key for create an instance  
LV\_OBJTYPE = 'SOFM'.  
LV\_OBJKEY  = WA\_DOCUMENT\_INFO-DOC\_ID.

Creating SOFM object

CALL FUNCTION 'SWO\_CREATE'  
     EXPORTING  
        OBJTYPE           = LV\_OBJTYPE  
        OBJKEY            = LV\_OBJKEY  
     IMPORTING  
        OBJECT            = LV\_SOFM  
        RETURN            = LV\_RETURN  
     EXCEPTIONS  
        NO\_REMOTE\_OBJECTS = 1  
        OTHERS            = 2.

* Prepare for attaching the object to container  
LV\_OBJJECT-HEADER = 'OBJH'.  
LV\_OBJECT-TYPE    = 'SWO'.  
LV\_OBJECT-HANDLE  = LV\_SOFM.  
APPEND LV\_OBJECT to TB\_OBJ.

Similarly prepare other attachments and append their details to tb\_obj internal table.  
Finally send the attachment details in the task container

CALL METHOD LV\_TAKS\_CONTAINER-&gt;SET  
      EXPORTING  
       NAME  = '\_ATTACH\_OBJECTS'  
       VALUE = TB\_OBJ\[].

* Commit the changes  
CALL METHOD IM\_WORKITEM\_CONTEXT-&gt;DO\_COMMIT\_WORK.

 

Now create the workflow in SWDD and in the user decision step give class ZTEST\_WFATTACH as a program exit.

 

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

 

Program exit would get triggered whenever user step is executed by the user.

 

Binding of user decision step:

 

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

 

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

 

Execution:

 

Once workflow is created you can associate with any event or you can directly execute it to check the result.

 

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

 

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

 

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

 

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

 

After reviewing the document user can take the necessary decision.