18 Replies Latest reply: May 2, 2013 8:44 AM by Stefan Riedel-Seifert RSS

BSP & DMS Document Download

Ideo Ideo
Currently Being Moderated

Hi All,

 

I'm developing a BSP which can download a folder with documents present in SAP's DMS, to c:\temp.

At the moment I use the EasyDMS function "Z_EASYDMS_FOLDER_EXPORT".

During development, it worked fine because I was going through the program in debug mode. Therefor, the SAPHTTP can connect with the SAP gui.

But when running "normallly" (not in debug), the program runs in error. It turns out that the SAPHTTP (nor SAPFTP) cannot connect and thus the documents cannot be downloaded.

I also tried to use call functions: CVAPI_DOC_CHECKOUTVIEW, SCMS_HTTP_GET_FILE and HTTP_GET_FILE, but all with no result. I also tried to call SAPFTP & SAPHTTP directly via "SYSTEM_START_REG_SERVER" and via the build of a command and the function "RFC_START_PROGRAM".

Again, with no result. The BSP runs in an error (HTTP 500 internal server error).

 

As this is an urgent development, help would be very much appreciated!!!

 

Regards,

 

Sander

  • Re: BSP & DMS Document Download
    Durairaj Athavan Raja
    Currently Being Moderated

    it looks like your Z function requires some SAP GUI functions and thats the reason why you are able to use it in debug and not in normal BSP mode.

     

    to over come this use FM

    BDS_BUSINESSDOCUMENT_GET_TAB to read the contents of the document and use the returned content to set it as the reponse of the page with proper mime type.

     

    Regards

    Raja

    • Re: BSP & DMS Document Download
      Ideo Ideo
      Currently Being Moderated

      Hi Raja,

       

      Thanks for the answer.

      But as I'm trying to download "real" documents (like Word, Excel) from SAP's Document Management System, I (think) cannot use the mentioned FM.

       

      Still looking for a solution......

       

       

      Kind regards,

       

      Sander Maes

    • Re: BSP & DMS Document Download
      Kathryn Mann
      Currently Being Moderated

      Durairaj,

       

      I am trying to use the BDS_BUSINESSDOCUMENT_GET_TAB function module you mentioned to retrieve the contents of all files attached to a particular notification.  The difficulty I am having is that it returns the contents of all attached files at once, in table "contents". 

       

      How can I determine which lines in "contents" are relevant to each file?

       

      I tried providing the components data for one file to restrict the "contents" results to the contents of just one file, but this did not limit the results. 

       

      Thank you for any assistance you can provide!

      Kathryn

  • Re: BSP & DMS Document Download
    Thomas Jung
    Currently Being Moderated

    The problem with the function modules that you have tried is that they are trying to send the content to the frontend for you - via the SAPGui - SAPHTTP and SAPFTP are executables with the SAPGui.

     

    What you want is a function module that will just return the binary content of the file to the ABAP application server.  You can then download this content to the client using your own mechanisms (there are serveral examples for download PDFs or Excel files in the BSP SDN weblogs if you need them). 

     

    I had a quick look and I think that SCMS_DOC_READ might just do the trick for getting the content.  It looks like it has logic to lookup the storage repository for the document (R3 database or via URL - filesystem or content/cache server) and access the content via the server side.

    • Re: BSP & DMS Document Download
      Ideo Ideo
      Currently Being Moderated

      Hi Thomas,

       

      Thx for the helpful answer. It's too bad that I can't trigger SAPHTTP or SAPFTP, because those are also used in the EasyDMS Gui with their own Z_EASYDMS* functions...

       

      I'm now trying to handle it the way you suggested, but do you know if it is possible to handle (download) more than 1 document? As far as I can tell (with limited bsp knowledge), I load the xstring of a file into page buffer. But how would it react to adding more than 1 file?

       

      Kind regards,

       

      Sander Maes

      • Re: BSP & DMS Document Download
        Thomas Jung
        Currently Being Moderated

        I usually just ZIP up multiple documents so that they can be all downloaded in one packages.  The ABAP class CL_ABAP_ZIP provides all the necessary function for compression and the creation of the ZIP package header.  The binary output from this class can be opened by any client side unzip utility.

        • Re: BSP & DMS Document Download
          George Knoske
          Currently Being Moderated

          Sander,

          Have you had any luck with your efforts to download the document?  My purpose is not in a BSP environment, but I simply wish to extract the document from DMS (postscript format in my instance), FTP or transfer to a server to be converted to PDF, and then returned to SAP where I will upload/create a DIR with the attached document as a PDF file.  As Thomas has noted CVAPI_DOC_CHECKOUTVIEW is preventing me from extracted the file anywhere but to my local PC, and since this application will be running in the background this does not suffice.  BAPI_DOCUMENT_CHECKOUTVIEW2 should accommodate this effort based upon parameters provided (PF_FTP_DEST), but I have been unsuccessful in getting this to work.  When trying to execute this BAPI in batch mode I receive errors that “program no longer started ia RFC…”.   Were are on release ECC6.

           

          George

      • Re: BSP & DMS Document Download
        N K
        Currently Being Moderated

        Hello Ideo,

         

        I'm facing the same problem of not being able to call SAP HTTP or SAP FTP, Were you able to successfully solve this if yes please share teh solution else please suggest alternatives.

         

        Thanks in advance

    • Re: BSP & DMS Document Download
      deepu k
      Currently Being Moderated

      Hello Thomas,

       

               I too need to get the documents from the DMS and display them in the BSP.

      In my case I have the folowing :-

       

      1. I created a BSP which will display the list of all the DOcuments available as in CV04N.

      2. Now I'm facing a problem to view the content for these list of documents.

      3. I too tried all the FM's : CVAPI , BAPI_DOCUMENT . But invain.

      4. I also went thru the standard SAP BSP's : CVAW_ENTIRE , CVAW_DOCUMENT_DISPLAY. This was also invain.

      5. I tried the FM specified by u : SCMS_DOC_READ .In this case I'm not able get the return values.

      I'm getting an error saying :

      **********************************************************************************************

      Error during import of physical document (DMS_C1, ) from cluster table DMS_CONT1_CD1

      **********************************************************************************************

      6. I have the following details with me :

       

                  I'm using the FM "CV120_KPRO_MASTER_DATA_GET" ans pass the

      DOKAR

      DOKNR

      DOKTL

      DOKVR.

      I'll get the following :

      • Logical document (LO_OBJID)

      • Application (PDF,DOC;XLS)

      • Physical Document (PH_OBJID)

      • Counter for documents (PH_INDEX)

      • Original of document (FILENAME: "C:\temp\Usermanagement.pdf" )

       

                         Now with this data I just want to open the file from the path given

      i.e "C:\temp\Usermanagement.pdf" and show it in my bsp.

       

      Can u suggest me the procedure ?

       

      Regards,

      Deepu.K

    • Re: BSP & DMS Document Download
      Krutheeka B
      Currently Being Moderated

      Hi Thomas,

       

      Like Kathryn said "

      I am trying to use the BDS_BUSINESSDOCUMENT_GET_TAB function module you mentioned to retrieve the contents of all files attached to a particular notification.  The difficulty I am having is that it returns the contents of all attached files at once, in table "contents". 

       

      How can I determine which lines in "contents" are relevant to each file?"

       

      I am having the same doubts too. Please enlighten me on this.

       

      Thanks in advance

      Krutheeka

  • Re: BSP & DMS Document Download
    abhishek sinha
    Currently Being Moderated

    Hi,

     

    Please follow the steps to Download a file from DMS or Display in Browser.

     

    1. Call BAPI  'BAPI_DOCUMENT_GETDETAIL2'

     

      call function 'BAPI_DOCUMENT_GETDETAIL2'

        exporting

          documenttype         = document_key-doctype

          documentnumber       = document_key-docnumber

          documentpart         = document_key-docpart

          documentversion      = document_key-docversion

          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.

     

    2. Then call BAPI_DOCUMENT_CHECKOUTVIEW2

     

    documentfile-wsapplication = it_documentfiles-wsapplication.

    call function 'BAPI_DOCUMENT_CHECKOUTVIEW2'

          exporting

            documenttype    = document_key-doctype

            documentnumber  = document_key-docnumber

            documentpart    = document_key-docpart

            documentversion = document_key-docversion

            documentfile    = documentfile

            getstructure    = '1'

            getheader       = 'X'

            pf_ftp_dest     = 'SAPFTPA'

          importing

            return          = lv_return

          tables

            documentfiles   = it_co_documentfiles.

     

    You need to pass PF_FTP_DEST as SAPFTPA as we are calling this FM from Browser not SAP GUI and if you dont pass this value then the FM errors out because it doesn't find SAP GUI.

     

    3. Now call SCMS_DOC_READ to get the Binary Data of the File.

     

    call function 'SCMS_DOC_READ'

        exporting

          mandt                 = sy-mandt

          stor_cat              = c_storage

          doc_id                = it_co_documentfiles-file_id

        tables

          access_info           = lt_access

          content_bin           = lt_sdokcntbin.

     

    IT_SDOKCNTBIN is the Binary Data Table of the file you want to download.

     

    Now you have the binary file data which you can write on Application Server or Convert it to XSTRING and show in a web dynpro application. I am not sure how to display in BSP.

    • Re: BSP & DMS Document Download
      Marc Cawood
      Currently Being Moderated

      We are successful in using this approach inside the GUI but not from Web Dynpro ABAP applications. Although we call BAPI_DOCUMENT_CHECKOUTVIEW2 with pf_ftp_dest = 'SAPFTPA' it failes in the browser with the following BAPIRET2-MESSAGE:

      No temprorary current directory for your frontend available

       

      Any help would be greatly appreciated.

    • Re: BSP & DMS Document Download
      Marc Cawood
      Currently Being Moderated
      Aha, it seems you CAN'T use this BAPI outside of SAPGUI but must instead use SCMS_DOC_READ!
      METHOD load_doc_xstring.
      **********************************************************************
        DATA: lt_files2          TYPE STANDARD TABLE OF bapi_doc_files2,
              ls_files2          TYPE bapi_doc_files2,
              ls_return          TYPE bapiret2,
              lt_bin             TYPE STANDARD TABLE OF sdokcntbin,
              lt_inf             TYPE STANDARD TABLE OF scms_acinf,
              ls_inf             TYPE scms_acinf.
      **********************************************************************
      
        CALL FUNCTION 'BAPI_DOCUMENT_GETDETAIL2'
          EXPORTING
            documenttype    = documenttype
            documentnumber  = documentnumber
            documentpart    = documentpart
            documentversion = documentversion
            getdocfiles     = 'X'
          IMPORTING
            return          = ls_return
          TABLES
            documentfiles   = lt_files2.
        IF LINES( lt_files2 ) > 1.
          RAISE EXCEPTION TYPE zcx_root EXPORTING textid = 'MULTIPLE_FILES'.
        ENDIF.
        READ TABLE lt_files2 INTO ls_files2 INDEX 1.
        IF sy-subrc NE 0.
          RAISE EXCEPTION TYPE zcx_root EXPORTING textid = 'NO_FILES'.
        ENDIF.
      
        CALL FUNCTION 'SCMS_DOC_READ'
          EXPORTING
            stor_cat    = 'ZCR01'
            doc_id      = ls_files2-file_id
          TABLES
            access_info = lt_inf
            content_bin = lt_bin.
        READ TABLE lt_inf INTO ls_inf INDEX 1.
        IF sy-subrc NE 0.
          RAISE EXCEPTION TYPE zcx_root EXPORTING textid = 'NO_FILE_INFO'.
        ENDIF.
      
        " Convert XData to Xstring
        CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
          EXPORTING
            input_length = ls_inf-comp_size
          IMPORTING
            buffer       = contentx
          TABLES
            binary_tab   = lt_bin
          EXCEPTIONS
            failed       = 1
            OTHERS       = 2.
        IF sy-subrc NE 0.
          RAISE EXCEPTION TYPE zcx_root EXPORTING textid = 'BINARY_CONVERSION_ERROR'.
        ENDIF.
      
        filename = ls_inf-comp_id.
      
      ENDMETHOD.
      
      
      • Re: BSP & DMS Document Download
        Renuka Sarode
        Currently Being Moderated

        Hi Marc,

        I have a similar requirement.

        I am  steps mentioned by  above by you.

        Could you pl tell me what is the contentx field in the FM 'SCMS_BINARY_TO_XSTRING'.

         

        Waiting for you response.

        Thankx in Advance.

        Regards,

        Renu

        • Re: BSP & DMS Document Download
          Marc Cawood
          Currently Being Moderated

          As the method name implies, it's an XSTRING. It can be saved to the SAP application server with:

           

          zcl_central_functions=>wda_upload_file( EXPORTING pi_file_destination = path pi_filecontent = contentx EXCEPTIONS OTHERS = 1 ).

           

          In our case we use our method load_doc_xstring to produce a series of files on the server which we then ZIP and send to the browser.

          • Re: BSP & DMS Document Download
            Renuka Sarode
            Currently Being Moderated

            Hi Marc,

            How to proceed further to open the file further?

            Ex:  While upload I have uploaded 3 files a word , txt and xl file with same documnet number.

            Next in display mode, i want to show these 3 files in a table and display the one that is selected.

            Problem i am facing here is , how to open the relevant file selected, using the data from the contentx using

            abap.

             

             

            Thanx in Advance,

            Regards,

            Renu

  • Re: BSP & DMS Document Download
    Stefan Riedel-Seifert
    Currently Being Moderated

    That's not difficult: Thera re a couple of FM's for this. If you have a http content server underlying for storing the document in SAP DMS, you may use

    SDOK_PHIO_GET_URL_FOR_GET

    SDOK_PHIO_GET_URL_FOR_GET_RFC

    to get a url to the doument in charge. The only thing you need is a physical object identifier - phio - to fille the only needed innput filed: objectID: class = 'DMS_PCD1'. objid is the phio. You may get the phio with BAPI documentgetDetail in the files table (phio = fileID).