Skip to Content

For few days I searched the better way to solve my problem that was HOW CAN I ATTACHMENT DMS FILE IN WORKITEM DECISION in my reseaches i found a lot of and different ways to do that but neither that solved completely my problem but now I know how to do and I’d like do share with everyone my solution.

First step you need to create a method in Business Object and the parameters do you need for select dms file but you can never forget to create a parameter type SOFM in this method.

Now write/copy the code below for convert dms file but before select table DRAW to find the object file and call functions for convert dms file and create a attachment document in workitem decision.

CALL FUNCTION ‘BAPI_DOCUMENT_GETDETAIL2’
EXPORTING
documenttype    = ‘ZCF’
documentnumber  = wl_draw-doknr
documentpart    = wl_draw-doktl
documentversion = wl_draw-dokvr
***    getcomponents        = ‘x’
***    getdocdescriptions   = ‘x’
***    getdocfiles          = ‘x’
***    getclassification    = ‘x’
IMPORTING
documentdata    = documentdata
return          = lv_return
TABLES
***    documentdescriptions = it_documentdescriptions
documentfiles   = it_documentfiles.
***    characteristicvalues = it_characteristicvalues
***    classallocations     = it_classallocations.

LOOP AT it_documentfiles INTO DATA(wa_documentfiles).

documentfile-documenttype = wl_draw-dokar.
documentfile-documentnumber = wl_draw-doknr.
documentfile-documentpart    = wl_draw-doktl.
documentfile-documentversion = wl_draw-dokvr.
documentfile-wsapplication = wa_documentfiles-wsapplication.

CALL FUNCTION ‘BAPI_DOCUMENT_CHECKOUTVIEW2’
EXPORTING
documenttype    = wl_draw-dokar
documentnumber  = wl_draw-doknr
documentpart    = wl_draw-doktl
documentversion = wl_draw-dokvr
documentfile    = documentfile
getstructure    = ‘1’
getheader       = ‘X’
***      pf_ftp_dest     = ‘*SAPFTPA*’
IMPORTING
return          = lv_return
TABLES
documentfiles   = it_co_documentfiles.

IF NOT it_co_documentfiles[] IS INITIAL.
READ TABLE it_co_documentfiles INTO DATA(wa_co_documentfiles) INDEX 1.
DATA(v_doc_id) = wa_co_documentfiles-file_id.
v_storage = wa_co_documentfiles-storagecategory.
ELSE.
v_doc_id  = wa_documentfiles-file_id.
v_storage = wa_documentfiles-storagecategory.
ENDIF.

Convert File to Binary mode using ID reference
CALL FUNCTION ‘SCMS_DOC_READ’
EXPORTING
mandt       = sy-mandt
stor_cat    = v_storage
doc_id      = v_doc_id
TABLES
access_info = lt_access
content_bin = lt_sdokcntbin.

READ TABLE lt_access INTO DATA(wl_access) INDEX 1.
Convert binary table to xtring and after that attachment xstring in workitem decision
CALL FUNCTION ‘SCMS_BINARY_TO_XSTRING’
EXPORTING
input_length = wl_access-comp_size
IMPORTING
buffer       = v_xstring
TABLES
binary_tab   = lt_sdokcntbin
EXCEPTIONS
failed       = 1
OTHERS       = 2.

wl_atthead-file_type = ‘B’.
wl_atthead-file_name = ‘Nota Fiscal/Miro’ && ‘:’ &&  space && object-key-documentno.
wl_atthead-file_extension = ‘PDF’.
wl_atthead-language       = ‘EN’.

CALL FUNCTION ‘SAP_WAPI_ATTACHMENT_ADD’
EXPORTING
workitem_id = v_father_wiid
att_header  = wl_atthead
att_bin     = v_xstring
IMPORTING
att_id      = v_attpdf.

ENDLOOP.

IF NOT v_attpdf-doc_id IS INITIAL.
pdf = v_attpdf-doc_id.
swc_set_element container ‘PDF’ pdf.
ENDIF.

But the solution not end here…now there is one more step for conclusion and solve the problem. Now open PFTC transaction and create a standard task as follow.

After that create a activite in business workflow and add the new standard task created in last step before a task decision with you want to attach the file.

Don’t forget binding the objects

The object below is my task decision

Finish the document were attached in workitem decision

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply