So, as you can see from the title, I had a very specific requirement. I needed to be able to create a document (those you can open through CV03N) programmatically attaching a file from the application server and with an FTP server that automatically assigns filenames.
I searched google/scn extensively for a way to do this or an example and tried a few, but it seems that the configuration options for DMS are so vast that it was unlikely to find an example that suited my needs and my configuration. So I’m sharing my code and my example, hoping that maybe it will be helpful for someone else, and maybe I’ll even need it myself in the future.
The code ended up being extremely simple, but I assure you I tried so many really complex approaches that I don’t even want to remind myself of them again
- lv_docty TYPE dokar,
- lv_docnr TYPE doknr,
- lv_docpr TYPE doktl_d,
- lv_docvr TYPE dokvr,
- ls_ret TYPE bapiret2,
- lt_files TYPE TABLE OF bapi_doc_files2,
- ls_files LIKE LINE OF lt_files,
- ls_documentdata TYPE bapi_doc_draw2.
- CLEAR ls_documentdata.
- ls_documentdata-documenttype = 'ZCL'.
- ls_documentdata-description = 'Testing DMS'.
- ls_documentdata-username = sy-uname.
- CLEAR ls_files.
- ls_files-originaltype = '1'.
- ls_files-storagecategory = '<VAULT NAME HERE>'.
- ls_files-docpath = '/tmp/'.
- ls_files-docfile = 'dms_test4.pdf'.
- ls_files-wsapplication = 'PDF'.
- APPEND ls_files TO lt_files.
- CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
- documentdata = ls_documentdata
- pf_ftp_dest = 'SAPFTPA'
- pf_http_dest = 'SAPHTTPA'
- documenttype = lv_docty
- documentnumber = lv_docnr
- documentpart = lv_docpr
- documentversion = lv_docvr
- return = ls_ret
- documentfiles = lt_files.
- IF ls_ret-type NE 'E'.
- CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
- wait = abap_true.
- CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
And the result:
I hope this will be helpful to someone!