Skip to Content

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:

Display Document_ Basic Data Customer Claim (ZCL).png

I hope this will be helpful to someone!

Best regards,

Bruno

To report this post you need to login first.

49 Comments

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

  1. Kjetil Kilhavn

    I am just struggling with this type of problem and was very happy to find your example. Unfortunately I get an upload error 😥

    In my case I am generating a file on the application server and it is to be stored in the SAP system/database (not using Knowledge Provider).

    When manually creating a document and attaching such a file it gets automatically assigned to SAP-SYSTEM as archive category. I have tried both with and without specification of this value to field “STORAGECATEGORY”, but have not solved the problem yet.

    Do you have any experience with that or a tip where I could start investigating?

    (0) 
    1. Bruno Esperança Post author

      Hi Kjetil!

      I’m glad my example made you happy somehow 🙂

      Like I said, before being successful I tried many more complex ways of achieving what I wanted. The best thing that I did was going home, sleeping, and coming back to office fresh the day after 🙂 My approach for the next day was: let’s simplify, and if it’s automatic, let’s leave it OUT of the equation.

      From what you’re telling me it seems you don’t have an FTP server configured, so, not only you should leave STORAGECATEGORY blank but also the pf_ftp_dest line should probably be commented out too, since there will be no FTP server (or at least that’s how it seems to me). You should also look around in configuration (SPRO – Cross-Application Components – Document Management – Control/General Data) to see how your DMS is configured, if you weren’t the one configuring it! 🙂

      It’s funny… your requirement seems to be easier than mine… but with SAP sometimes easier is more difficult! 😀

      Good luck… keep me posted of your results. I could actually extend my document to include your case and your solutions. This way it will be easy to find for us if we ever need it in the future! 🙂

      Regards,

      Bruno

      (0) 
      1. Kjetil Kilhavn

        In another thread (‘BAPI_DOCUMENT_CREATE2’: store attachment using ‘SAP-SYSTEM’) I found an important piece of information – the files which are not to be stored using Knowledge Provider are supplied as part of the document data (BAPI_DOC_DRAW2) structure.

        So, by filling the fields DOCFILE1, DATACARRIER1 (“SAP-SYSTEM”) and WSAPPLICATION1 the original file got added and checked in – at least so it appears.

        Now I get an error (26/254) when trying to display the original, but at least I got one step further – I think and hope.

        (0) 
        1. Bruno Esperança Post author

          Hi Kjetil,

          Glad you’re making some progress 🙂

          Error while opening the file… At first glance I would say maybe the file you are trying to open is not maintained in the workstation application customizing table. Check transaction code DC30 or search for “Define Workstation Application” in SPRO. That would be my best guess…

          I just looked at the error message… Error while checking out… so I don’t think it’s what I just said. Maybe debugging will help you? 🙁

          I don’t think I have this set up so that I can store documents in SAP-SYSTEM, otherwise I would try to have a look as well.

          Good luck!

          Bruno

          (0) 
          1. Kjetil Kilhavn

            After trying to solve the checkout problem for hours and hours without getting any wiser I debugged far enough down in the SAP code to discover that the check-in is the problem. There is no content in table DRAO for the originals I have attached after creating them on the server. 😥

            (0) 
            1. Bruno Esperança Post author

              Hi Kjetil,

              Well… at least that’s some progress!! 🙂

              I see table DRAO being used in Web Dynpro component LFS_SUST_FILEUPLOAD. If you look at method PROCESS_EVENT in its component controller you see very interesting code that might be helpful for you. Namely:

              CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY’

                          EXPORTING: buffer        = lf_content

                          IMPORTING: output_length = lv_len

                          TABLES:    binary_tab    = lt_binary.

              LOOP AT lt_binary ASSIGNING <fs>.

                       ls_draoorblk = <fs>line.

                       ls_draoorln  = lv_len.

                       APPEND ls_drao TO lt_content.

                       ADD 1 TO ls_draozaehl.

              ENDLOOP.


              See if that helps!!


              Regards,

              Bruno

              (0) 
  2. Kjetil Kilhavn

    Sorry about taking so long before updating this thread, but here is the solution that turned out to work in my case.

    First of all, the case can be described as follows:
    – Document type is not using Knowledge Provider

    – Original file is a small text file created on the fly in a web service implementation

    – Original file stored in the TMP area during web service execution

    The solution in our case ended along the following pseudo-code lines:

    1) Create original file on server TMP area (with fixed name)

    2) Call BAPI_DOCUMENT_CREATE2 – not passing on original created in step 1

    3) Call BAPI_TRANSACTION_COMMIT (if creation was successful, otherwise exit)

    4) Read file from server

    5) Convert text file contents to binary content format using SCMS_STRING_TO_XSTRING followed by SCMS_XSTRING_TO_BINARY

    6) Attach original to document using CVAPI_DOC_CHECKIN

    The first and fourth steps could probably be skipped, i.e. the file contents could be passed on directly to SCMS_STRING_TO_XSTRING, but I haven’t touched it much after I finally got it working 🙂

    (0) 
    1. Former Member

      Hi kjetil/bruno,

                         i am also stuck up with same kind of requirment.here,i am having the document content downloaded from xECm to my internal table in xstring format.now,i want to store it in a word file in application server without saving it in presentation layer .can you please guide me.

      Regards,

      Krishna.

      (0) 
      1. Bruno Esperança Post author

        Hi Krishna,

        I think the easiest way for you is to create this document in a temporary location in the application server using the OPEN DATASET statement, and then follow my instructions above.

        I believe that the OPEN DATASET need the data in binary format, but you should be able to find a way to convert easily by searching the forum.

        If you encounter any specific issues please share the code and maybe we help.

        Good luck.

        Kind regards,

        Bruno

        (0) 
        1. Former Member

          Hi bruno,

               1. created a file in application server using the opendata set stmt.

                     open dataset dsn for output in binary mode .

          loop at lt_binary into wa_binary .

          transfer wa_binary to file .

          endloop.

          while sy-subrc = 0 .

          transfer file to result .

          endwhile.

          close dataset file .

            now ,when i open the file in the al11 …it is opening in unreadable format.

          i want to display the file in word document .without downloading it in to presentation layer.

          (0) 
          1. Bruno Esperança Post author

            Hi Krishna,

            I’m not really sure what you are trying to achieve. To open and display a file you always have to create a local copy. For example, when you are browsing the internet and you choose to “open” a file instead of saving it, a local copy is created in your temporary files, and then eventually it gets deleted when you clear the temporary files from the browser cache.

            Best regards,

            Bruno

            (0) 
            1. Former Member

              hi bruno ,

                           the requirment is to control the printing of the document ,previously while printing they are updating the document in the dms using ole.but,now the dms is replaced by xECM .from xecm we are getting the document attachment as xstring .

                          we can edit the document by downloading it into  presentation server .but the requirment is to control the printing of the document ,hence we have to achive printing of the document by user  without downloading  it into the presntation layer.

              please share your mail id ,so that i can share code also.

              Regards,

              Krishna.

              (0) 
              1. Bruno Esperança Post author

                Hi Krishna,

                I don’t think I can help you much further with this. Try and open a new question and share your code (or the relevant parts). Hopefully you will get help from people more knowledgeable than me 🙂

                Regards,

                Bruno

                (0) 
    1. Bruno Esperança Post author

      Hi Omer,

      I do not, I’m sorry, and I don’t have the time right now to look into that. But regarding the e-mail part look into standard class CL_BCS. Class CL_ZIP is also useful if you want to send the attachments in ZIP format.

      Good luck and best regards,

      Bruno

      (0) 
  3. Former Member

    Hi Bruno,

    Thanks a lot for the code. We do have a similar requirement.  The documents from one system have to be migrated to another system.

    Initially we are reading the DIR details using the FM “BAPI_DOCUMENT_GETDETAIL2 “.

    Then converting the document files data to xstring using the FM’s  ‘SDOK_PHIO_LOAD_CONTENT’ and ‘SCMS_XSTRING_TO_BINARY’ .

    Then I am saving the file to local system(Presentation server) using cl_gui_frontend_services=>gui_download . (This process of saving locally is to get the physical path for checking in the document using FM  ‘BAPI_DOCUMENT_CREATE2’

    ).

    So far the above procedure is working fine as it is foreground. But now the requirement is to run report in background. I am sure the gui_download will not wotk in background. Alternatively has to use opendataset and closedataset in application server.

    My query is, if I use the opendataset method here, how to use the SAPHTTPA and SAPFTPA .

    Thanks in advance.

    Siva   

    (0) 
    1. Bruno Esperança Post author

      Hi Siva!

      You are very welcome.

      I also use the application server. The path to the file in the application server should go in fields “docpath” and “docfile” in the “documentfiles” table.

      I guess the only difference from my scenario to your scenario, is that you don’t use a VAULT to store the file in SAP. I would try a code similar to mine but without populating the storage category (line 18 on my code).

      Give it a try… if it doesn’t work, I guess you’ll have to do a lot of debugging, like I did 🙂

      Best regards,

      Bruno

      (0) 
      1. Former Member

        Hi Bruno,

        Thanks for the reply.

        I am able to save the file on application server and able to see in AL11 tcode. But when I am trying to checkin the document using the below FM.

        CALL FUNCTION ‘BAPI_DOCUMENT_CREATE2’
           EXPORTING
             documentdata               = ls_doc
             pf_ftp_dest     = ‘SAPFTPA’
             pf_http_dest    = ‘SAPHTTPA’
          IMPORTING
            documenttype                  = ls_stbdokar
            documentnumber             = ls_stbdoknr
            documentpart                   = ls_stbdoktl
            documentversion              = ls_stbdokvr
            return                                = ls_return
          TABLES
              documentfiles              lt_documentfiles.

        It is throwing the follow error.

        Error while checking in and storing: /usr/sap/tmp/200372_001.TIF

        Please help me on this issue.

        Thanks,

        Siva Krishna

            .

        (0) 
        1. Bruno Esperança Post author

          Hi Siva,

          Very hard for me to help you 🙁 If you’d like to share the entire code I could try to run it when I have some spare time (very rare these days) and see if I can find anything, but the SAP DMS can be configured in many different ways, so I’m pretty sure my results wouldn’t be the same as yours.

          My advice to you is to do the same as I did, get some coffee, some relaxing music, and debug the standard step by step.

          Good luck,

          Bruno

          (0) 
    2. Former Member

      Hi Siva,

      I am trying something similar. Lets say I have a doc no = 111. And it has 1 file as attachment.

      I want to get that file in xstring format so that I can show that in my web dynpro(FPM) application.

      How can I get the xstring format? Can you kindly detail it a bit.

      Many many thanks i advance.

      Regards,

      Saikat

      (0) 
  4. Former Member

    Hello Bruno,

    nice example but i don’t get the part where you are attaching file from application server.

    I have my file on application server in directory DIR_HOME with path looks like  F:\usr\sap\T60\….. and

    ls_documentfilesSTORAGECATEGORY = ‘DMS_C1_ST’.

    ls_documentfilesWSAPPLICATION = ‘WW7’.

    ls_documentfilesDOCPATH = ‘F:/usr/sap/T60/DVEBMGS01/work/’.

    ls_documentfilesDOCFILE = ‘dms01.docx’.

    ls_documentfilesDESCRIPTION = ‘DOCUMENT WORD 3’.


    i get error: Error while checking in and storing:

    F:/usr/sap/T60/DVEBMGS01/work/dms01.docx


    So my question is you have in your code:

    ls_filesdocpath = ‘/tmp/’.

    ls_filesdocfile = ‘dms_test4.pdf’.



    So where is this file located?


    Thanks

    Miro

    (0) 
    1. Bruno Esperança Post author

      Hi Miro,

      As far as I know, when you are accessing a file from the application server, you don’t need the drive letter. So I think if you remove “F:” from the path, it should work.

      I would troubleshoot this trying simple examples with the OPEN DATASET statement.

      If you still have trouble, let me know, I can try to look further into this, but at the moment I’m a bit busy.

      Best regards,

      Bruno

      (0) 
        1. Bruno Esperança Post author

          Hi Miroslav,

          Not really, no 😕

          And even if I had the time to dig into it, my system is probably configured in a different way so I’m not sure if I would be able to replicate your issue.

          My only advice to you is to do the same thing I did… many hours of debugging… 🙂

          Cheers and good luck,

          Bruno

          (0) 
  5. Former Member

    Hi Bruno,

    Great artcles.

    I am trying something similar. Lets say I have a doc no = 111. And it has 1 file as attachment.

    I want to get that file in xstring format so that I can show that in my web dynpro(FPM) application.

    How can I get the xstring format? Can you kindly detail it a bit.

    Many many thanks i advance.

    Regards,

    Saikat

    (0) 
    1. Bruno Esperança Post author

      Hi Saikat,

      This reply is almost one year too late but maybe it will be helpful for others.

      When you have your file in binary format (by using OPEN DATASET), you can use function module SCMS_BINARY_TO_XSTRING to convert it to XSTRING format.

      Regards,
      Bruno

      (0) 
  6. Jayadan .

    Hi Bruno

    Nice document.It helped me a lot. Even i am getting the same error like mirosalv and siva was talking. Any heads up for this error and how it could be solved.  Error while checking in and storing: my file path. Thanks in advance.

    (0) 
  7. Jayadan .

    Hi Burno

    Nice document and it was very helpful and thanks for it first of all. As mirosalv and siva saying even I am getting the same error “Error While Checking in and storing: my file path”. Any idea why I am getting this and how it could be solved if so please let me know and Thanks in advance.

    (0) 
    1. Bruno Esperança Post author

      Hi Jayadan,

      As already replied to others, there are so many different ways that DMS can be configured, I’m not sure I’d be able to replicate your error. But looking at the error message, it looks like there might be an issue in the way the file name is being generated? Also, if you use it via dialog, are you able to store files? Could be missing some customizing.

      Good luck,
      Bruno

      (0) 
  8. Former Member

    Hi Burno,

    Nice knowledge sharing documents , I have work around it it help help to me upload document after refereing above document .

    thanks Burno.

     

    (1) 
  9. Former Member

    Hi Bruno,

    I read all comment in this blog and find very helpful for other scenario. My scenario is little different.

    I have a program which runs daily to move all invoice attachment from GoS to Content server. In report i am using FM  ARCHIVOBJECT_CREATE_TABLE and  ARCHIV_CONNECTION_INSERT to move the attachment. After moving the attachment i am able to open the pdf document but not able to open word/excel file. content is getting corrupted and while opening the file it’s asking to convert. Please suggest if i am missing any config. I have configured the word file in DC30 tcode

    Below is DC30 line for word document. One more point.. after adding entry in DC30 it started working but after EHP8 upgrade it’s not working. Please suggest.

    WRD Word   A2

     

    Best Regards,

    Srikanth

     

    (1) 
    1. Bruno Esperança Post author

      I don’t think I’m able to help, my apologies. If you would post more information, such as the code where you make the conversions from one format to another, maybe someone with more experience in that specific scenario would be able to help you. One thing I would be extremely careful with, is the actual “zeros and ones” of the files. Make sure the underlying file system is similar and use raw data as much as possible.

      Cheers.

      (0) 
      1. Sar CRM

        Hi Bruno,

        I have a small question on DMS..i am getting attachments from web service I see we need to store files temporarily(Desktop/Application server) if we use the FM 
        SPAN {
        font-family: “Courier New”;
        font-size: 10pt;
        color: #000000;
        background: #FFFFFF;
        }
        BAPI_DOCUMENT_CREATE2  as we have file path as one of the Inputs for FM.

        is there any way we can avoid temporarily storing the files into the app server and can directly upload files to DMS..?

        I really appreciate your help on this.

         

         

        Thanks,

        SarSAP.

         

        (0) 
        1. Bruno Esperança Post author

           

          Hi,

          The application server is not a “front-end” desktop. This would be a huge problem. What I did, and I think this is mandatory, is to store the file in a temporary folder of the SAP system (application server), and after the file is checked-in to the vault server, I delete the temporary file.

          So, to answer your question, I think the answer is no, you have to store the file temporarily in the application server, but there’s no “desktop”, the path should be something like /usr/sap/tmp or something like that.

          Cheers,
          Bruno

          (0) 
  10. Former Member

    Hi Bruno,

    I am able to successfully create a DIR with the document in application server. If I want to pick the document from another FTP location/my computer’s local directory then what should i pass in the host name and how the RFC destination SAPFTPA  should be configured. Please advice. Also how should we pass the below values in case of FTP/local directory.

    1. ls_files-docpath = ‘/tmp/’.
    2. ls_files-docfile = ‘dms_test4.pdf’.

     

     

    Regards

    IK

    (0) 
    1. Bruno Esperança Post author

      Hi,

      I may be wrong, but I think you need to keep in mind that the BAPI that was used is basically a programmatic  way of creating a document in SAP’s DMS (or basically, the same as transaction CV01N). So I guess you need to configure the FTP location in SAP’s DMS, but honestly I’m not an expert in this topic. I just stumbled upon a way of doing what I wanted to do, and shared in case someone has a similar requirement, but I can’t really support people on this.

      Cheers,
      Bruno

      (0) 
  11. Borner Frederic

    Hi,

    one of my first post, hopefully I will not be out of scope 🙂

    I had a similar issue to create a Document info Record linked to an object and with files to be checked. The problem is that files are saved in an internal table as binaries and not stored somewhere on the server nor on the local PC of the user.

    So I wrote that function module which fulfilled my requirements:

    FUNCTION z_fm_ca_set_docments_to_dms.
    *"----------------------------------------------------------------------
    *"*"Local Interface:
    *"  IMPORTING
    *"     VALUE(IS_DOCUMENT) TYPE  BAPI_DOC_DRAW2
    *"     VALUE(IT_LINK) TYPE  TT_BAPI_DOC_DRAD OPTIONAL
    *"     VALUE(IT_FILES) TYPE  ZCA_DMS_FILE_2_TT OPTIONAL
    *"  EXPORTING
    *"     VALUE(ET_RETURN) TYPE  BAPIRET2_TAB
    *"----------------------------------------------------------------------
      DATA: lt_objectlink     TYPE          tt_bapi_doc_drad,
            lt_objectlink_new TYPE          tt_bapi_doc_drad,
            lt_content        TYPE TABLE OF drao,
            lt_files          TYPE TABLE OF cvapi_doc_file,
            lt_comp_x         TYPE TABLE OF cvapi_doc_comp,
            lt_binary         TYPE TABLE OF orblk.
    
      DATA: ls_document TYPE bapi_doc_aux,
            ls_data     TYPE bapi_doc_draw2,
            ls_message  TYPE messages,
            ls_return   TYPE bapiret2.
    
      DATA: lv_file_size TYPE i.
    
      ls_data = is_document.
    
      IF ls_data-documenttype IS INITIAL.
        ls_data-documenttype    = zif_ps_cmt_m=>mc_dms_defaults-dms_type. "'GEN'
      ENDIF.
    
    * DMS document does not exist yet, create it.
      IF is_document-documentnumber  IS INITIAL AND
         is_document-documentpart    IS INITIAL AND
         is_document-documentversion IS INITIAL.
        CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
          EXPORTING
            documentdata    = is_document
            pf_ftp_dest     = zif_ca_constants=>gc_dms_ftp_rfc
            pf_http_dest    = zif_ca_constants=>gc_dms_http_rfc
          IMPORTING
            documenttype    = ls_document-doctype
            documentnumber  = ls_document-docnumber
            documentpart    = ls_document-docpart
            documentversion = ls_document-docversion
            return          = ls_return.
    *      TABLES
    *        objectlinks     = lt_objectlink.
    
        APPEND ls_return TO et_return.
    
        IF ls_return-type NA /srmsmc/if_supplier_c=>gc_message_types_failure.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait = 'X'.
        ENDIF.
      ENDIF.
    
      lt_objectlink_new = it_link.
    
      IF NOT lt_objectlink_new IS INITIAL AND ls_return-type NA /srmsmc/if_supplier_c=>gc_message_types_failure.
        CLEAR: ls_return.
    
        CALL FUNCTION 'BAPI_DOCUMENT_GETOBJECTLINKS'
          EXPORTING
            documenttype    = ls_document-doctype
            documentnumber  = ls_document-docnumber
            documentpart    = ls_document-docpart
            documentversion = ls_document-docversion
          IMPORTING
            return          = ls_return
          TABLES
            objectlinks     = lt_objectlink.
    
        APPEND ls_return TO et_return.
    
    *   Only add links that do not exist yet.
        LOOP AT lt_objectlink REFERENCE INTO DATA(lr_link).
          DELETE lt_objectlink_new WHERE objectkey  = lr_link->objectkey
                                     AND objecttype = lr_link->objecttype.
        ENDLOOP.
    
        IF NOT lt_objectlink_new IS INITIAL AND ls_return-type NA /srmsmc/if_supplier_c=>gc_message_types_failure.
          CLEAR: ls_return.
    
          CALL FUNCTION 'BAPI_DOCUMENT_SAVEOBJECTLINKS'
            EXPORTING
              documenttype    = ls_document-doctype
              documentnumber  = ls_document-docnumber
              documentpart    = ls_document-docpart
              documentversion = ls_document-docversion
            IMPORTING
              return          = ls_return
            TABLES
              objectlinks     = lt_objectlink_new.
    
          APPEND ls_return TO et_return.
    
          IF ls_return-type NA /srmsmc/if_supplier_c=>gc_message_types_failure.
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
              EXPORTING
                wait = 'X'.
          ENDIF.
        ENDIF.
      ENDIF.
    
    * Add files to created document
      IF NOT it_files IS INITIAL AND ls_return-type NA /srmsmc/if_supplier_c=>gc_message_types_failure.
        LOOP AT it_files REFERENCE INTO DATA(lr_file).
          CLEAR: lt_binary, lv_file_size, lt_content, lt_files.
    
          CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
            EXPORTING
              buffer          = lr_file->rawfile
              append_to_table = abap_false
            IMPORTING
              output_length   = lv_file_size
            TABLES
              binary_tab      = lt_binary.
    
          LOOP AT lt_binary REFERENCE INTO DATA(lr_binary).
            APPEND INITIAL LINE TO lt_content ASSIGNING FIELD-SYMBOL(<fs_content>).
            <fs_content>-dokar = ls_document-doctype.
            <fs_content>-doknr = ls_document-docnumber.
            <fs_content>-dokvr = ls_document-docversion.
            <fs_content>-doktl = ls_document-docpart.
            <fs_content>-zaehl = sy-tabix.
            <fs_content>-orln  = lv_file_size.
            <fs_content>-orblk = lr_binary->*.
            DESCRIBE FIELD <fs_content>-orblk LENGTH <fs_content>-orbkl IN BYTE MODE.
          ENDLOOP.
    
          APPEND INITIAL LINE TO lt_files ASSIGNING FIELD-SYMBOL(<fs_file>).
          <fs_file>-dttrg          = ls_document-dttrg.
          <fs_file>-storage_cat    = lr_file->storagecategory.
    
          IF <fs_file>-storage_cat  IS INITIAL.
            <fs_file>-storage_cat  = zif_ca_constants=>gc_dms_default_storage. "'DMS_C1_ST'
          ENDIF.
    
          <fs_file>-langu          = sy-langu.
          <fs_file>-pathname       = lr_file->docpath.
    *      <fs_file>-filename       = lr_attachment->docfile.
          <fs_file>-description    = lr_file->description.
          <fs_file>-created_at     = lr_file->created_at.
          <fs_file>-created_by     = lr_file->created_by.
          <fs_file>-changed_at     = lr_file->changed_at.
          <fs_file>-changed_by     = lr_file->changed_by.
          <fs_file>-file_id        = lr_file->file_id.
          <fs_file>-dappl          = lr_file->wsapplication.
          <fs_file>-appnr          = lr_file->originaltype.
    
          IF <fs_file>-appnr IS INITIAL.
            <fs_file>-appnr = zif_ca_constants=>gc_dms_original_view_only. "'1'
          ENDIF.
    
          <fs_file>-active_version = abap_true.
    
          IF <fs_file>-dappl IS INITIAL.
    *       Get corresponding application type
            CALL FUNCTION 'CV120_DOC_GET_APPL'
              EXPORTING
                pf_file   = lr_file->docfile
              IMPORTING
                pfx_dappl = <fs_file>-dappl.
          ENDIF.
    
    
          CALL FUNCTION 'CVAPI_DOC_CHECKIN'
            EXPORTING
              pf_dokar           = ls_document-doctype
              pf_doknr           = ls_document-docnumber
              pf_dokvr           = ls_document-docversion
              pf_doktl           = ls_document-docpart
    *         PS_DOC_STATUS      =
              pf_ftp_dest        = zif_ca_constants=>gc_dms_ftp_rfc  "'SAPFTPA'
              pf_http_dest       = zif_ca_constants=>gc_dms_http_rfc "'SAPHTTPA'
    *         PF_HOSTNAME        = ' '
    *         PS_API_CONTROL     =
              pf_replace         = abap_true
              pf_content_provide = 'TBL'
            IMPORTING
              psx_message        = ls_message
            TABLES
              pt_files_x         = lt_files
    *         pt_comp_x          = lt_comp_x
              pt_content         = lt_content.
    
          CLEAR ls_return.
          MOVE-CORRESPONDING ls_message TO ls_return.
          APPEND ls_return TO et_return.
    
          IF ls_return-type NA /srmsmc/if_supplier_c=>gc_message_types_failure.
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
              EXPORTING
                wait = 'X'.
          ENDIF.
        ENDLOOP.
      ENDIF.
    ENDFUNCTION.

    The function is quite simple as it creates first the DMS document is no document number is passed in structure “IS_DOCUMENT”, the add new linked objects passed in table “IT_LINKS” and finally for each row of table IT_FILES, convert the xstring to a binary table, get required details default values like application type, etc… (which are part of the customizing of DMS).

    Commits after each steps are required to avoid error like “Document XXX does not exist”.

    Hope it might help.

    (1) 

Leave a Reply