cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Attachment in workflow task not working

Former Member
0 Likes
3,760

Hi All,

I know there are several posts regarding the attachment of PDF file in a workflow item, But i have tried all solutions given under them and still attachment is not working.

My requirement is to attach a PDF when PO is released. For this i have created a ZBUS2012 with  Z method. In that method i have created a RFC to get data from SRM server.

I have passed the XSTRING data of a smartform using convert_otf to the 'SAP_WAPI_ATTACHMENT_ADD' and the att_bin parameter is getting populated. As suggested by various posts i have tried the following code for attaching

swc_set_element container 'SOFM'  att_id-doc_id

After this I have done the binding in task with SOFM.

And after this i have done binding of workflow container i.e. SOFM from task to Attach_objects.

Thanks in advance

Accepted Solutions (0)

Answers (1)

Answers (1)

bpawanchand
Active Contributor
0 Likes

Hi Mohit,

It would be great if you can post the instance of container,  However I would ask you to check upon executiong of SWC_CREATE_OBJECT what is the value of sy-subrc.

Do you find any item under objects and attachments  when the workitem is placed in the user 's inbox.

If it is available then what's the error raised when you try to click on the attachment, is it some thing related to "FOlder Not found"...

Elaborate more on this.

Regards

Pavan

Former Member
0 Likes

Hi,

I have not used SWC_CREATE_OBJECT.

I have just writen   swc_set_element container 'SOFM'  att_id-doc_id.


Regards

Mohit Vashist

anjan_paul
Active Contributor
0 Likes

Hi,

Can you see any attachemnt in the workitem, if you see but after clicking, pdf not opening, then it is a conversion problem.

But if you are not able to see any attachment at all, then binding problem.

Put  a breakpoint and try to debuig it

Former Member
0 Likes

Hi,

There is no attachment. The values are passing correctly. In the step GET_DETAILS i have writen the code in Z Method and passing att_id-doc_id to  SOFM Container.

After this in the Release of purchase order step i have done binding of the attach_objects.

In T-Code SWI1 it showing the data getting passed. But still no attachment is there.

Kindly help me resolve this issue.

Regards

Mohit Vashist

anjan_paul
Active Contributor
0 Likes

Hi,

Can you share how you use 'SAP_WAPI_ATTACHMENT_ADD'

Former Member
0 Likes

Hi,

I am passing the data using  RFC from SRM Server. The smartform is comverted by using CONVERT_OTF.

    CALL FUNCTION FM_NAME
    EXPORTING
      CONTROL_PARAMETERS = LA_CTRL_FORM
      OUTPUT_OPTIONS     = LA_OUTPUT_OPT
      P_OBJ_TYPE         = P1_OBJECT_TYPE
    IMPORTING
      JOB_OUTPUT_INFO    = JOB_OUPUT
    TABLES
      LT_FINAL_HEADER    = LT_FINAL_HEADER
    EXCEPTIONS
      FORMATTING_ERROR   = 1
      INTERNAL_ERROR     = 2
      SEND_ERROR         = 3
      USER_CANCELED      = 4
      OTHERS             = 5.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  REFRESH LT_OTFDATA.

  LT_OTFDATA[] = JOB_OUPUT-OTFDATA[].

  CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
    EXPORTING
      I_OTF                    = LT_OTFDATA
    EXCEPTIONS
      CONVERT_OTF_TO_PDF_ERROR = 1
      CNTL_ERROR               = 2
      OTHERS                   = 3.

  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  DATA: L_DUMMY TYPE STANDARD TABLE OF TLINE.

**line commented  for mohit
*   PDF_SIZE TYPE I.
  CLEAR: PDF_DATA, PDF_SIZE.

* convert otf to pdf
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      FORMAT                = 'PDF'
      MAX_LINEWIDTH         = 255
    IMPORTING
      BIN_FILESIZE          = PDF_SIZE
      BIN_FILE              = PDF_DATA
    TABLES
      OTF                   = LT_OTFDATA[]
      LINES                 = L_DUMMY
    EXCEPTIONS
      ERR_MAX_LINEWIDTH     = 1
      ERR_FORMAT            = 2
      ERR_CONV_NOT_POSSIBLE = 3
      OTHERS                = 4.

  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


The PDF_DATA retrived from FM is Passed in 'SAP_WAPI_ATTACHMENT_ADD'

Regards

Mohit Vashist

anjan_paul
Active Contributor
0 Likes

Hi,

'CONVERT_OTF is already used in SSFCOMP_PDF_PREVIEW. So why you used it in your method?

Also share your custom method interface parameter screenshot

Former Member
0 Likes

Hi,

CONVERT_OTF was in the existing code in the SRM Server. I have just made a RFC Returing the DATA from CONVERT_OTF to ECC Server.

I have writen the following code in the Zmethod.

    CALL FUNCTION 'ZRFC_PO_EMAIL_ATTACHMENT' DESTINATION 'SRDCLNT333'
       EXPORTING REQ_NO = wa_ekpo-BEDNR
       IMPORTING PDF_DATA = PDF_DATA
                 PDF_SIZE = PDF_SIZE.

SWC_GET_ELEMENT CONTAINER 'WORKITEMID' workitemid.


ZSWR_ATT_HEADER-FILE_TYPE = 'B'.
ZSWR_ATT_HEADER-FILE_NAME = 'TEST'.
ZSWR_ATT_HEADER-FILE_EXTENSION = 'PDF'.
ZSWR_ATT_HEADER-LANGUAGE = 'EN'.

CALL FUNCTION 'SAP_WAPI_ATTACHMENT_ADD'
  EXPORTING
    WORKITEM_ID            = workitemid
    ATT_HEADER             = ZSWR_ATT_HEADER
*   ATT_TXT                =
    ATT_BIN                = PDF_DATA
*   DOCUMENT_OWNER         = SY-UNAME
*   LANGUAGE               = SY-LANGU
*   DO_COMMIT              = 'X'
*   COMMENT_SEMANTIC       = ' '
IMPORTING
    RETURN_CODE            = gd_subrc
    ATT_ID                 = ZSWR_ATT_ID
* TABLES
*   MESSAGE_LINES          =
*   MESSAGE_STRUCT         =
          .
  SWC_SET_ELEMENT CONTAINER 'ZSWR_ATT_ID' ZSWR_ATT_ID.

  SWC_SET_ELEMENT CONTAINER 'SOFM' ZSWR_ATT_ID-DOC_ID.

*  swc_create_object SOFM 'SOFM' ZSWR_ATT_ID-DOC_ID.

I have follow the following blof for the development

http://scn.sap.com/docs/DOC-3039

In this he is converting PDF to binary and than binary to xstring.

I think there is a problem in the PDF_DATA which I am passing to 'SAP_WAPI_ATTACHMENT_ADD'.

how to convert smartform to the type which is to be passed in   ATT_BIN  of 'SAP_WAPI_ATTACHMENT_ADD'.

Please find the below SS of parameters of the zmethod

Thanks in advance.

Regards

Mohit Vashist

anjan_paul
Active Contributor
0 Likes

hi,

  your SOFM is marked as Import only, but not Export

Mark Export and try it

Former Member
0 Likes

done... but still no attachment

anjan_paul
Active Contributor
0 Likes

Hi,

      Check and share, how you bind SOFM from method to task and task to workflow in every step

Former Member
0 Likes

Hi,

Can I have your email ID to share the document.

My ID is mohitvashist.1987@gmail.com

Regards

Mohit Vashist

anjan_paul
Active Contributor
0 Likes

Hi,

  Maintained in my profile. You can share here also, then other expert can share their view

Former Member
0 Likes

Hi,

Your mail id is not visible in your profile. Please find the process Screen shots below.

CODE for Z Method in ZBUS2012 -->

BEGIN_METHOD ZGET_DETAIL CHANGING CONTAINER.
DATA:
      VAR3 LIKE BAPIEKKOL,
      VAR1 LIKE BAPIEKKOL.

data : it_ekpo type table of ekpo with header line,
       gs_total_final type kwert,
       var2 type wfsyst-initiator,
       init_name type string.
*SWC_GET_ELEMENT CONTAINER 'PoHeader' VAR1.
SWC_GET_ELEMENT CONTAINER 'initiator' VAR2.
select * from ekpo into table it_ekpo
     where ebeln = object-key-purchaseorder and loekz eq ''.
*select * from ekpo into table it_ekpo where ebeln = var1-po_number
*                                         and loekz eq ''.

loop at it_ekpo.
  gs_total_final = gs_total_final + it_ekpo-NETWR.
endloop.
SWC_SET_ELEMENT CONTAINER 'POAmount' gs_total_final.
SWC_SET_ELEMENT CONTAINER 'initiator_name' init_name.

************Begin of code for Attachment************************
DATA: wa_ekpo TYPE ekpo,
      ZSWR_ATT_HEADER TYPE SWR_ATT_HEADER,
      SOFM TYPE swc_object,
      ZSWR_ATT_ID TYPE SWR_ATT_ID,
      IT_SOLIX_TAB TYPE solix-LINE OCCURS 0,
      wa_solix TYPE solix-LINE,
      PDF_DATA TYPE  XSTRING,
      PDF_SIZE TYPE I,
      zxstring TYPE xstring,
      GD_SUBRC TYPE SY-SUBRC,
      workitemid TYPE SWR_STRUCT-WORKITEMID,
      ld_no TYPE i.
SORT: it_ekpo by ebeln ebelp.

ld_no = 5.

WHILE ld_no = 5.

ENDWHILE.

READ TABLE it_ekpo INTO wa_ekpo INDEX 1.
IF sy-subrc eq 0.
  CALL FUNCTION 'ZRFC_PO_EMAIL_ATTACHMENT' DESTINATION 'SRDCLNT333'
       EXPORTING REQ_NO = wa_ekpo-BEDNR
       IMPORTING PDF_DATA = PDF_DATA
                 PDF_SIZE = PDF_SIZE.

SWC_GET_ELEMENT CONTAINER 'WORKITEMID' workitemid.


ZSWR_ATT_HEADER-FILE_TYPE = 'B'.
ZSWR_ATT_HEADER-FILE_NAME = 'TEST'.
ZSWR_ATT_HEADER-FILE_EXTENSION = 'PDF'.
ZSWR_ATT_HEADER-LANGUAGE = 'EN'.

CALL FUNCTION 'SAP_WAPI_ATTACHMENT_ADD'
  EXPORTING
    WORKITEM_ID            = workitemid
    ATT_HEADER             = ZSWR_ATT_HEADER
*   ATT_TXT                =
    ATT_BIN                = PDF_DATA
*   DOCUMENT_OWNER         = SY-UNAME
*   LANGUAGE               = SY-LANGU
*   DO_COMMIT              = 'X'
*   COMMENT_SEMANTIC       = ' '
IMPORTING
    RETURN_CODE            = gd_subrc
    ATT_ID                 = ZSWR_ATT_ID
* TABLES
*   MESSAGE_LINES          =
*   MESSAGE_STRUCT         =
          .
  SWC_SET_ELEMENT CONTAINER 'ZSWR_ATT_ID' ZSWR_ATT_ID.

  SWC_SET_ELEMENT CONTAINER 'SOFM' ZSWR_ATT_ID-DOC_ID.

*  swc_create_object SOFM 'SOFM' ZSWR_ATT_ID-DOC_ID.

ENDIF.
************End of Chnages************************************
END_METHOD.

CODE in SRM Server for RFC -->

FM is exporting

PDF_DATA TYPE XSTRING

PDF_SIZE TYPE I

   CALL FUNCTION FM_NAME
    EXPORTING
      CONTROL_PARAMETERS = LA_CTRL_FORM
      OUTPUT_OPTIONS     = LA_OUTPUT_OPT
      P_OBJ_TYPE         = P1_OBJECT_TYPE
    IMPORTING
      JOB_OUTPUT_INFO    = JOB_OUPUT
    TABLES
      LT_FINAL_HEADER    = LT_FINAL_HEADER
    EXCEPTIONS
      FORMATTING_ERROR   = 1
      INTERNAL_ERROR     = 2
      SEND_ERROR         = 3
      USER_CANCELED      = 4
      OTHERS             = 5.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  REFRESH LT_OTFDATA.

  LT_OTFDATA[] = JOB_OUPUT-OTFDATA[].

  CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
    EXPORTING
      I_OTF                    = LT_OTFDATA
    EXCEPTIONS
      CONVERT_OTF_TO_PDF_ERROR = 1
      CNTL_ERROR               = 2
      OTHERS                   = 3.

  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  DATA: L_DUMMY TYPE STANDARD TABLE OF TLINE.

**line commented  for mohit
*   PDF_SIZE TYPE I.
  CLEAR: PDF_DATA, PDF_SIZE.

* convert otf to pdf
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      FORMAT                = 'PDF'
      MAX_LINEWIDTH         = 255
    IMPORTING
      BIN_FILESIZE          = PDF_SIZE
      BIN_FILE              = PDF_DATA
    TABLES
      OTF                   = LT_OTFDATA[]
      LINES                 = L_DUMMY
    EXCEPTIONS
      ERR_MAX_LINEWIDTH     = 1
      ERR_FORMAT            = 2
      ERR_CONV_NOT_POSSIBLE = 3
      OTHERS                = 4.

  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

Regards

Mohit Vashist

anjan_paul
Active Contributor
0 Likes

Hi,

check your method is not in release status.

Try to put a debug point in your custom method and check SOFM is populated properly or not

Former Member
0 Likes

Hi,

As suggested by you, I have done the entire steps the mail is getting triggered and the attachment is passing to SAP INBOX. But the problem is the notification goint to the external email ID is not containg the PDF Attachment.

Please suggest ...

Thanks in advance..

anjan_paul
Active Contributor
0 Likes

Hi,

How you passed to external userid?

Former Member
0 Likes

We are using standard SAP Program to Pass WorkItem to Approvers External Mail ID