Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
bruno_esperanca
Contributor

Hi all,

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

  1. DATA:
  2.       lv_docty  TYPE dokar,
  3.       lv_docnr  TYPE doknr,
  4.       lv_docpr  TYPE doktl_d,
  5.       lv_docvr  TYPE dokvr,
  6.       ls_ret    TYPE bapiret2,
  7.       lt_files  TYPE TABLE OF bapi_doc_files2,
  8.       ls_files  LIKE LINE OF lt_files,
  9.       ls_documentdata TYPE bapi_doc_draw2.
  10. CLEAR ls_documentdata.
  11. ls_documentdata-documenttype = 'ZCL'.
  12. ls_documentdata-description = 'Testing DMS'.
  13. ls_documentdata-username = sy-uname.
  14. CLEAR ls_files.
  15. ls_files-originaltype = '1'.
  16. ls_files-storagecategory = '<VAULT NAME HERE>'.
  17. ls_files-docpath = '/tmp/'.
  18. ls_files-docfile = 'dms_test4.pdf'.
  19. ls_files-wsapplication = 'PDF'.
  20. APPEND ls_files TO lt_files.
  21. CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
  22.   EXPORTING
  23.     documentdata    = ls_documentdata
  24.     pf_ftp_dest     = 'SAPFTPA'
  25.     pf_http_dest    = 'SAPHTTPA'
  26.   IMPORTING
  27.     documenttype    = lv_docty
  28.     documentnumber  = lv_docnr
  29.     documentpart    = lv_docpr
  30.     documentversion = lv_docvr
  31.     return          = ls_ret
  32.   TABLES
  33.     documentfiles   = lt_files.
  34. IF ls_ret-type NE 'E'.
  35.   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  36.     EXPORTING
  37.       wait = abap_true.
  38. ELSE.
  39.   CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
  40. ENDIF.

And the result:

I hope this will be helpful to someone!

Best regards,

Bruno

55 Comments