Skip to Content
avatar image
Former Member

Convert Internal Table to Attachment in Workflow

Hello Workflow Gurus,

I have a workflow were business asked me to include a changelog in the workitem description of the approval workitem sent to the SAP inbox and to the user email. I have the data in an internal table in my Class Method (i am using a Class instead of a BOR for my custom enhancements to the Workflow), however, if i pass this data to the workitem description it will get truncated since the data is too long (fieldname, field old value (char256),filed new value (char256), date of change, time of change).

I decided to try to convert the internal table to a PDF document or any other document and pass it as attachment as follows:

LOOP AT wc_changelog "This table has the data taht i need to display

INTO ls_changelog.

" I concatenate all the data to a text string separating each column by '|'.

CONCATENATE ls_changelog-fldname ls_changelog-f_old ls_changelog-f_new ls_changelog-udate ls_changelog-utime INTO ls_text SEPARATED BY '|'.

APPEND ls_text TO lt_text.

ENDLOOP.

CALL FUNCTION 'SCMS_TEXT_TO_BINARY'

IMPORTING

output_length = lv_length

TABLES

text_tab = lt_text

binary_tab = lt_binary

EXCEPTIONS

failed = 1

OTHERS = 2.

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF. " IF sy-subrc <> 0

CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'

EXPORTING

input_length = lv_length

IMPORTING

buffer = lv_doc_string

TABLES

binary_tab = lt_binary

EXCEPTIONS

failed = 1

OTHERS = 2.

IF sy-subrc EQ 0.

ls_swr_att_header-file_type = 'B'.

ls_swr_att_header-file_name = 'Changes Log'.

ls_swr_att_header-file_extension = 'PDF'.

ls_swr_att_header-language = sy-langu.

CALL FUNCTION 'SAP_WAPI_ATTACHMENT_ADD'

EXPORTING

workitem_id = wc_workitemid

att_header = ls_swr_att_header

* ATT_TXT =

att_bin = lv_doc_string

document_owner = sy-uname

language = sy-langu

do_commit = 'X'.

ENDIF. " IF sy-subrc EQ 0

I am creating a new attachment in my workflow and i am passing this attachment to the workitem that is sent to the users inbox, however i am getting a message saying that the fiel type has been damaged and i am not able to open it.

Please your help with any suggestions to correct the code and pass the internal table to any kind of attachment to the Workflow or to pass it displaying correctly to the workitem description. Any help will be greatly appreciated.

Regards,

Gustavo

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Apr 07, 2016 at 10:41 PM

    There is a problem displaying tables in workflow task description, so I usually recommend displaying the data as text (<fieldname> change from:<old> to <new> at...) in a table of one long field (for example swf_lines-line).

    Although the old and new fields in your example are 256 chars long, the values or the changed data are not that long, so this should work. (at the worst case you will need to add another line)

    P.S

    I don't think that the way you wrote is the way to create a PDF file. but that is a question for a different forum.

    Add comment
    10|10000 characters needed characters exceeded