cancel
Showing results for 
Search instead for 
Did you mean: 

Issue in adding the PDF attachment to user decision work item

jagesh_lakdawala
Active Participant
0 Kudos

Hi Experts,

In my scenario,  I have a User decision step and i want to attach the existing smart form as PDF attachment

to the work item of user decision step itself.

for achiving this i have used the Program Exit Tab of the User decision step; i have created one class which has implemented the standard

SAP interface IF_SWF_IFS_WORKITEM_EXIT. Within the method EVENT_RAISED, i have written the following logical steps.

     below steps will work only after work item creation event, i.e. SWRCO_EVENT_AFTER_CREATION

  • got the work item Id of the user decision step through the method import parameter
  • got the OTF data for the existing smart form and converted them to the XSTRING format using the FM CONVERT_OTF.
  • used the FM SAP_WAPI_ADD_ATTACHMENT as shown below.

             IST_OTF_DATA[] = GD_JOB_OUTPUT-OTFDATA.

              CALL FUNCTION 'CONVERT_OTF'

                EXPORTING

                  FORMAT                = 'PDF'

                  MAX_LINEWIDTH         = 10

                IMPORTING

                  BIN_FILESIZE          = GD_PDF_LENGTH

                  BIN_FILE              = GD_PDF_XSTRING

                TABLES

                  OTF                   = IST_OTF_DATA

                  LINES                 = IST_LINES

                EXCEPTIONS

                  ERR_MAX_LINEWIDTH     = 1

                  ERR_FORMAT            = 2

                  ERR_CONV_NOT_POSSIBLE = 3

                  ERR_BAD_OTF           = 4

                  OTHERS                = 5.

         

                     LS_FILE_HEADER-FILE_TYPE = 'B'.
                      CONCATENATE SY-DATUM SY-UZEIT 'MYFILE' INTO LS_FILE_HEADER-FILE_NAME.  "File name
                      LS_FILE_HEADER-FILE_EXTENSION = 'PDF'.
                      LS_FILE_HEADER-LANGUAGE = 'EN'.


                      refresh: LST_SWR_MESSAG,LST_SWR_MSTRUC.
                      CALL FUNCTION 'SAP_WAPI_ATTACHMENT_ADD'
                        EXPORTING
                          WORKITEM_ID          = LV_ID   "work item ID
                          ATT_HEADER           = LS_FILE_HEADER
                          ATT_BIN              = GD_PDF_XSTRING   "Parameter FM CONVERT_OTF
                         DOCUMENT_OWNER       = SY-UNAME
                       IMPORTING
                         RETURN_CODE          = LS_RETURN_CODE
                         ATT_ID               = LS_ATTCH_ID
                       TABLES
                         MESSAGE_LINES        = LST_SWR_MESSAG
                         MESSAGE_STRUCT       = LST_SWR_MSTRUC.

Issue is: after executing this FM, LS_RETURN_CODE value is 7; LST_SWR_MESSAG contains message as 'Unable to create attachment'

LST_SWR_MSTRUC contains 1 row as message ID SWR and message no 220.

Work item does not contain any attachment.

please do the needful.

Regards,

Jagesh

Accepted Solutions (0)

Answers (1)

Answers (1)

ronen_weisz
Active Contributor
0 Kudos

Here is how I attach documents to tasks ,try it. it's easier to debug, takes less space from the DB, and you don't need program exits.

jagesh_lakdawala
Active Participant
0 Kudos


Hi Ronen,

Thanks for your answer. i dont have much idea on the approach you mentioned in ur reply.

so i am looking for the SOFM object related approach.

please do the needful.

Regards,

Jagesh

ronen_weisz
Active Contributor
0 Kudos

Hi, the reason I use this way is because it bypasses problems such as your attachment error, it is closer to the regular way PDFs or attachments are displayed in other programs (if it works for the standard display - it will work for you) that is why I started using z-objects.

Any way (SOFM or z-object)  I would recommend you do add the attachment in the program exit but as an attribute (or using a task to create the object) since it will be easier to test and to see problems in the log.

jagesh_lakdawala
Active Participant
0 Kudos

Hi,

It looks like an issue of insufficient authorization or some other issue in application server configuration because same code is working fine on other application server.

There is no issue in the code which I posted in opening thread.

Regards,

Jagesh