cancel
Showing results for 
Search instead for 
Did you mean: 

File format when uploading files from BSP to DMS

Former Member
0 Kudos

Hi, I recently posted a message about uploading and checking in a file to DMS from a BSP. It works now , except that when I go to DMS and open the file, the format is corrupted. When I check in the file, I convert the file content to binary format, and I am guessing that when I open the file, it is displayed in binary format... In my code below, which data type should the structure ls_bintab be ? Can anyone help ?

data ?= CL_HTMLB_MANAGER=>GET_DATA(

request = runtime->server->request

name = 'fileUpload'

id = 'FIL' ).

data : l_content type xstring.

data : lt_content type standard table of DRAO.

data : ls_content type DRAO.

data : binlen type i.

data : begin of ls_bintab,

line(2550),

end of ls_bintab .

data : lt_bintab LIKE table of ls_bintab.

data : ldoctype type DRAW-DOKAR,

ldocnumber type DRAW-DOKNR,

ldocversion type DRAW-DOKVR,

ldocpart type DRAW-DOKTL,

docstatus type CVAPI_DOC_STATUS.

data : ls_message type messages.

data : documentfiles type table of CVAPI_DOC_FILE.

data : documentfiles_s type CVAPI_DOC_FILE.

  • convert xstring to itab

l_content = data->file_content .

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = l_content

IMPORTING

output_length = binlen

TABLES

binary_tab = lt_bintab.

ldoctype = 'ZT3'.

ldocnumber = 'TEST ZT3'.

ldocversion = '01'.

ldocpart = '000'.

docstatus-DOKST = 'ER'.

concatenate 'Entered' sy-datum INTO docstatus-STATUSLOG separated by space.

  • fill internal table lt_content

  • switch to an itab with structure DRAO

ls_content-mandt = sy-mandt.

ls_content-appnr = '1'.

ls_content-orln = binlen.

ls_content-orbkl = 2550 .

ls_content-DOKAR = ldoctype.

ls_content-DOKNR = ldocnumber.

ls_content-DOKVR = ldocversion.

ls_content-DOKTL = ldocpart.

LOOP AT lt_bintab INTO ls_bintab.

ls_content-orblk = ls_bintab-line.

ls_content-zaehl = ls_content-zaehl + 1.

APPEND ls_content TO lt_content.

ENDLOOP.

documentfiles_s-DAPPL = 'ZWD'.

documentfiles_s-APPNR = '1'.

documentfiles_s-STORAGE_CAT = 'Z_TADCAT'.

documentfiles_s-DTTRG = 'DEFAULT'.

data : path type filep,

fname type filep,

curr_char(1),

fl type i.

fl = strlen( data->file_name ) - 1.

curr_char = data->file_name+fl.

while curr_char NE '\' AND fl GT 0.

fl = fl - 1.

curr_char = data->file_name+fl.

endwhile.

fl = fl + 1.

path = data->file_name(fl).

fname = data->file_name+fl .

documentfiles_s-PATHNAME = path .

documentfiles_s-FILENAME = fname .

documentfiles_s-DESCRIPTION = 'test document zt3 second'.

documentfiles_s-ACTIVE_VERSION = 'X'.

append documentfiles_s TO documentfiles.

  • Check in, contenttype = TBL

call function 'CVAPI_DOC_CHECKIN'

EXPORTING

pf_dokar = ldoctype

pf_doknr = ldocnumber

pf_dokvr = ldocversion

pf_doktl = ldocpart

PS_DOC_STATUS = docstatus

pf_content_provide = 'TBL'

IMPORTING

psx_message = ls_message

TABLES

pt_files_x = documentfiles

pt_content = lt_content.

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I think the problem is your declaration of ls_bintab. You are declaring your line as line(2550). This would create a character field. Should it not be line(255) type x.

Here is an example from standard SAP (CL_INCL_DOC_FILES->_checkin) that is very close to what you are doing:


 types: begin of t_xdata,
           line(2550) type x,
         end of t_xdata.

  data: lt_xdata    type table of t_xdata,
        lt_drao     type table of drao,
        lt_files    type table of cvapi_doc_file,
        ls_file     type cvapi_doc_file,
        ls_drao     type drao,
        ls_api_cntl type cvapi_api_control,
        ls_msg      type messages.

  data: lf_req      type ref to if_http_entity,
        lf_content  type xstring,
        lf_mimetype type string,
        lf_mime     type tdwp-mimetype,
        lf_filename type string,
        lf_size     type i,
        lf_n        type i,
        lf_num      type i.

  field-symbols: <fs> type t_xdata.
...
**--------------------------------------------------------------------------------
* Checkin document
**--------------------------------------------------------------------------------
  call function 'SCMS_XSTRING_TO_BINARY'
       exporting: buffer        = lf_content
       importing: output_length = lf_size
       tables:    binary_tab    = lt_xdata.

  loop at lt_xdata assigning <fs>.
    clear ls_drao.
    ls_drao-orblk = <fs>-line.
    ls_drao-orln  = lf_size.
    append ls_drao to lt_drao.
  endloop.

About the only difference I can see is the use of line(2550) type x.

Message was edited by: Thomas Jung - Sorry typo in the original postings code sample. I didn't want to confuse anyone. I line(255) type x instead of line(2550) type x.

Answers (3)

Answers (3)

murali_ram
Participant
0 Kudos

Hi Thomas

Need your help ..Am also facing same kind of issue...am able to upload pdf document from webdynpro to DMS. am able to see the uploaded pdf file in the dms ..but i cant able to open it.. it says i cant able to open.. please help on this...

Here is my code.

i used attributes : File_name  of char255

                         file_type  of string

                         file_contents of xstring.

CODE :

DATA lo_nd_n_upload TYPE REF TO if_wd_context_node.

    DATA lo_el_n_upload TYPE REF TO if_wd_context_element.

    DATA lt_n_upload TYPE TABLE OF wd_this->element_n_upload. " Internal Table

    DATA ls_n_upload TYPE wd_this->element_n_upload. " Work Area

    DATA lv_fileupload TYPE wd_this->element_n_upload-file_contents.

    TYPES: BEGIN OF zst_ts_raw_line,

*            line TYPE sdokcntbin,

             line(2550) TYPE x,

           END OF zst_ts_raw_line.

    DATA: ls_draw TYPE draw,

          ls_api_ctrl TYPE cvapi_api_control,

          ls_message TYPE messages,

          lv_documentnumber TYPE draw-doknr,

          lv_storage_cat TYPE cv_storage_cat,

          lv_size TYPE i,

          lt_bindata TYPE STANDARD TABLE OF zst_ts_raw_line, "STANDARD TABLE OF zst_ts_raw_line,

          ls_bindata TYPE sdokcntbin, "SOLISTI1," sdokcntbin,

          ls_drao TYPE drao,

          lt_drao TYPE TABLE OF drao,

          lt_files TYPE cvapi_tbl_doc_files,

          ls_files TYPE cvapi_doc_file,

          l_string TYPE string,

          lv_dokar TYPE draw-dokar,

          lv_dokvr TYPE draw-dokvr

          .

    DATA: it_drat TYPE TABLE OF dms_db_drat,

          wa_drat TYPE dms_db_drat.

* navigate from <CONTEXT> to <N_UPLOAD> via lead selection

    lo_nd_n_upload = wd_context->get_child_node( name = wd_this->wdctx_n_upload ).

*   @TODO handle non existant child

*   IF lo_nd_n_upload IS INITIAL.

*   ENDIF.

*  get element via lead selection

    lo_el_n_upload = lo_nd_n_upload->get_element( ).

* @TODO handle not set lead selection

    IF lo_el_n_upload IS NOT INITIAL.

*     get single attribute

      lo_el_n_upload->get_attribute(

      EXPORTING

        name = `FILE_CONTENTS`

      IMPORTING

        value = lv_fileupload ).

*     get all declared attributes

      lo_el_n_upload->get_static_attributes(

        IMPORTING

          static_attributes = ls_n_upload ).

      IF ls_n_upload IS NOT INITIAL.

*       ls_draw-dokar = 'ISH'.

*       ls_draw-dokvr = '00'.

*       ls_draw-doktl = '000'.

*       ls_draw-dwnam = sy-uname.

**        ls_draw-dokst = 'CD'.

*       ls_draw-begru = '1000'.

*       lv_storage_cat = 'DMS_C1_ST'.

*       ls_api_ctrl-tcode = 'CV01N'.

        ls_draw-dokar = 'TS2'.

        ls_draw-dokvr = 'AA'.

        ls_draw-doktl = '000'.

        ls_draw-doknr = '000020000491-I'.

        ls_draw-dwnam = sy-uname.

*        ls_draw-dokst = 'CD'.

        ls_draw-begru = '1000'.

        lv_storage_cat = 'DMS_C1_ST'.

        ls_api_ctrl-tcode = 'CV01N'.

        wa_drat-dktxt = 'Description'.

        APPEND wa_drat TO it_drat.

*       For Generate Document Number in DMS

        CALL FUNCTION 'CVAPI_DOC_CREATE'

          EXPORTING

            ps_draw              = ls_draw " wa_documentfiles

*         PF_STATUSLOG         = ' '

*         PF_REVLEVEL          =

            ps_api_control       = ls_api_ctrl

*         PF_FTP_DEST          = ' '

*         PF_HTTP_DEST         = ' '

*         PF_HOSTNAME          = ' '

*         PF_CONTENT_PROVIDE   = ' '

          IMPORTING

            psx_message          = ls_message

*         PFX_DOKAR            =

            pfx_doknr            = lv_documentnumber

*         PFX_DOKVR            =

*         PFX_DOKTL            =

          TABLES

*         PT_DRAD_X            =

            pt_drat_x            = it_drat

*         PT_FILES_X           =

*         PT_COMP_X            =

*         PT_CONTENT           =

*         DOCUMENTDESCRIPTIONS =

          .

        IF sy-subrc NE 0.

          WRITE: 'no number'.

        ENDIF.

        IF ls_message-msg_type CA 'EA'.

        ELSE.

          ls_draw-doknr = lv_documentnumber.

*         For Unpack Text : (Text Binary)

          CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

            EXPORTING

              buffer          = lv_fileupload

*           APPEND_TO_TABLE = ' '

            IMPORTING

              output_length   = lv_size

            TABLES

              binary_tab      = lt_bindata.

          LOOP AT lt_bindata INTO ls_bindata.

            CLEAR ls_drao.

            ls_drao-orblk = ls_bindata-line.

            ls_drao-orln = lv_size.

            ls_drao-dokar = ls_draw-dokar.

            ls_drao-doknr = lv_documentnumber.

            ls_drao-dokvr = ls_draw-dokvr.

            ls_drao-doktl = ls_draw-doktl.

            ls_drao-appnr = '1 '.

            APPEND ls_drao TO lt_drao.

          ENDLOOP.

*         For Application Determined on the basis of file extension.

          CALL FUNCTION 'CV120_DOC_GET_APPL'

            EXPORTING

*             PF_DIALOG        =

*             PF_DISPLAY       =

              pf_file          = ls_n_upload-file_name " 'C:\Documents and Settings\AUTH.PDF'

*             PF_TYPDT         =

           IMPORTING

             pfx_dappl        = ls_files-dappl

*           TABLES

*             PTX_TDWP         =

                    .

          ls_files-appnr = '1'.

          ls_files-filename = ls_n_upload-file_name. " 'C:\Documents and Settings\AUTH.PDF'

          ls_files-updateflag 'I'.

          ls_files-langu = sy-langu.

          ls_files-storage_cat = 'DMS_C1_ST'.

          ls_files-description 'Doc Description'.

*          ls_files-checked_in = 'X'.

*          ls_files-active_version = 'X'.

          APPEND ls_files TO lt_files.

*         For Execute external Commit when using BAPIs

          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

            EXPORTING

              wait = 'X'.

*         Document Check.

          CALL FUNCTION 'CVAPI_DOC_CHECKIN'

            EXPORTING

              pf_dokar           = ls_draw-dokar

              pf_doknr           = lv_documentnumber

              pf_dokvr           = ls_draw-dokvr

              pf_doktl           = ls_draw-doktl

*           PS_DOC_STATUS      =

              pf_ftp_dest        = 'SAPFTPA'

              pf_http_dest       = 'SAPHTTPA'

*           PF_HOSTNAME        = ' '

              ps_api_control     = ls_api_ctrl

*           PF_REPLACE         = ' '

              pf_content_provide = 'TBL'

            IMPORTING

              psx_message        = ls_message

            TABLES

              pt_files_x         = lt_files

*           PT_COMP_X          =

              pt_content         = lt_drao.

          COMMIT WORK.

        ENDIF.

CLEAR: ls_draw, ls_message, ls_api_ctrl, wa_drat.

        CLEAR: lt_drao[], lt_files[], it_drat[].

      ENDIF. "



    Looking for your help to solve this

Former Member
0 Kudos

iT finally works !! line(2550) type x does it, but line(255) type X gave me a quite strange popup telling me the file could not be accessed... probably because of the line ls_content-orbkl = 2550 further down. Thanks for your help Thomas,

Mireille

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Sorry about that. The line(255) type X was a typo that I corrected, but probably not before you saw the posting. Also I don't believe that edits go out in the watch e-mails.

athavanraja
Active Contributor
0 Kudos

can you try converting your lt_bintab

to

data : lt_bintab type standard table of xstring.

Regards

Raja

Former Member
0 Kudos

Hi Raja, I tried it but the function module SCMS_XSTRING_TO_BINARY creates a short dump if I pass an internal table of type XSTRING. Thanks anyways,

Mireille