Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Create an SAP DMS document attaching a file from the Application Server and checking in an FTP vault with automatic filename creation

$
0
0

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  TYPETABLE OF bapi_doc_files2,
  8.       ls_files  LIKELINE 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-typeNE'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:

 

Display Document_ Basic Data Customer Claim (ZCL).png

 

I hope this will be helpful to someone!

 

Best regards,

Bruno


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>