Skip to Content
Author's profile photo Former Member

Sending multiple attachments in the user decision step of workflow

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

WF flow diagram.png

                                                   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

Function EXit.png

  

Go to SE24, implement method EVENT_RAISED of interface IF_SWF_IFS_WORKITEM_EXIT   ZTEST_WFATTACH is created for the same.

class interface.png

/wp-content/uploads/2012/09/method_141172.png

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->GET_WORKITEM_ID
RECEIVING
RE_WORKITEM = LV_ID.

* Fetch Container
CALL METHOD IM_WORKITEM_CONTEXT->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->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 <L_XLINE> CASTING.
CONCATENATE PDF_XSTRING <L_XLINE>      
INTO PDF_XSTRING IN BYTE MODE.
ENDLOOP.

* Create and set document
IT_SOLIX_TAB1 = CL_DOCUMENT_BCS=>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->SET
EXPORTING
NAME  =
‘_ATTACH_OBJECTS’
VALUE = TB_OBJ[].

* Commit the changes
CALL METHOD IM_WORKITEM_CONTEXT->DO_COMMIT_WORK.

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


Program exit would get triggered whenever user step is executed by the user.
Binding of user decision step:

  /wp-content/uploads/2012/09/binding_141112.png
    /wp-content/uploads/2012/09/binding1_141119.png

Execution:

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

WF1.png

WF2.png

  WF3.png

       WF4.png

   After reviewing the document user can take the necessary  decision.

Assigned Tags

      13 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Thorsten Rams
      Thorsten Rams

      Hi Lokesh,

      you created a very helpful document.

      But I am lost with the declaration of variables.

      What type do these variables have: lv_object and TB_OBJ?

      Thank you very much for your help.

      Best regards,

      Thorsten

      Author's profile photo Thorsten Rams
      Thorsten Rams

      Hi Lokesh,

      after a long session of debugging and searching I found the answer myself.

      I guess for everybody who is new to the matter I guess it will be helpful.

      In the exit class (implementing IF IF_SWF_IFS_WORKITEM_EXIT) you have to include the type group SWC0.

      Then the declaration is as follows:

      DATA:

      lv_object TYPE swc0_object,

      tb_obj LIKE TABLE OF lv_object.

      Best regards,

      Thorsten

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Thorsten,

      Sorry couldn't respond to you query yesterday.

      Yes you have to include SWCO.

      thanks for telling everyone.

      regards,

      Lokesh

      Author's profile photo matala vamsi
      matala vamsi

      Hi Lokesh,

      I have query in the document you have posted how do i get spool number lv_spool.

      please help i am stuck at that point.

      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.

      Author's profile photo Former Member
      Former Member

      Hi Lokesh,

      We are using similar means in our project to add attachments to workflow step,but we are facing issues when attaching .docx and .xlsx attachemnts . We infact passed the filename into  object_header parameters of FM- SO_DOCUMENT_INSERT_API1.

      Still this is not working . User when viewing from workflow approver step,not able to open .docx and .xlsx attachements. Please advice.

      Regards,

      Viji

      Author's profile photo Rick Bakker
      Rick Bakker

      Hello,

      You should open a new thread and give more details:

      What error message are they seeing?

      Can they open other .xlsx files?

      regards

      Rick

      Author's profile photo Rama Sudhakar
      Rama Sudhakar

      Hello Lokesh,

      nice work buddy, it help me in my implementation,

      Thanks and Regards

      Sudhakar

      Author's profile photo Murali Krishna
      Murali Krishna

      Helpful information.... Thanks for sharing ...

      Author's profile photo ajeet choudhary
      ajeet choudhary

      can anyone tell me how to get value of spool number LV_SPOOL field here.

      Regards

      Ajit

      Author's profile photo Former Member
      Former Member

      Can anyone tell  me what is the declaration type of lwa_pdfline and <l_xline>. I am getting error in this assignment.

      Also,how to handle exceptions here?

      Regards

      Pooja

      Author's profile photo Sunil Maurya
      Sunil Maurya

      Please tell me about the declarations of variables(types) in the given code.

      Regards

      Sunil

      Author's profile photo Former Member
      Former Member

      Declarations I used for this code.

      DATA: LV_ID TYPE SWW_WIID,
            LV_CONTAINER TYPE REF TO IF_SWF_IFS_PARAMETER_CONTAINER,
            LV_ATTACH TYPE TABLE OF OBJ_RECORD,
            LV_FOLDER_ID TYPE REF TO SOODK,
      
            LV_SPOOL TYPE TSP01-RQIDENT,
            LA_BYTE_COUNT TYPE I,
            GT_PDF TYPE TABLE OF TLINE,
            LWA_PDFLINE TYPE TLINE,
            PDF_XSTRING TYPE XSTRING,
      
            IT_SOLIX_TAB1 TYPE SOLIX_TAB,
            LV_DATA TYPE SODOCCHGI1,
            WA_DOCUMENT_INFO TYPE SOFOLENTI1,
            LV_OBJTYPE TYPE SWOTOBJID-OBJTYPE,
            LV_OBJKEY TYPE SWOTOBJID-OBJKEY,
            LV_SOFM TYPE SWOTRTIME-OBJECT,
            LV_RETURN TYPE SWOTRETURN,
      
            LV_OBJECT TYPE OBJ_RECORD,
            TB_OBJ TYPE TABLE OF OBJ_RECORD.

      Regards,

      fergonara.

      Author's profile photo Andrea Frati
      Andrea Frati

      hi , i can't find declaration for   <l_xline>

      can you help me ?