Skip to Content

How to attach file to document (like CV01N does)

Hi!

I need to attach a file to a document. The problem is that the file is stored in binary format in a database Z-table. These files come from other system via XI and saved to the table in background task.

BAPI_DOCUMENT_CHECKIN2 doesn't suit because it can upload files only from local GUI or, may be, application server. Creating temporary file on an application server probably will not help because there is number of servers and file can be placed on any of them.

Help please!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Apr 04, 2008 at 12:05 AM

    Hi,

    How did you resolved this issue? I am facing same problem.

    Thanks!

    Nilesh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 30, 2008 at 11:51 AM

    Hi,

    Am running smiliar problem , here i have placed the my file in the XI file path ,

    When i run the FM in the ERP backend system it works fine attaching the file to the Document.

    But well when i use the same the FM in XI and pass samr paramters using mapping and execute it doesnot attach but there is no error.

    Seeing this i tested this FM called from SRM system where this FM is not present i made a remote call using the Destination , it worked in executing the FM but the file is not attached , there is no error message.

    How to make this FM executed via xi ?? WAS IT DONE ?/ KINDLY ADVICE

    SRINI

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi!

      The problem was resolved with following function module:

      FUNCTION Zzzz.

      *"----


      ""

      *" IMPORTING

      *" VALUE(DOKAR) LIKE DRAW-DOKAR

      *" VALUE(DOKNR) LIKE DRAW-DOKNR

      *" VALUE(DOKVR) LIKE DRAW-DOKVR

      *" VALUE(DOKTL) LIKE DRAW-DOKTL

      *" REFERENCE(FILECONTENT) TYPE STRING

      *" VALUE(FULLFILENAME) TYPE STRING DEFAULT 'C:\TEMP.DOC'

      *" VALUE(DAPPL) TYPE DAPPL DEFAULT 'WRD'

      *" VALUE(MIMETYPE) TYPE W3CONTTYPE DEFAULT 'application/msword'

      *" EXCEPTIONS

      *" NODOCUMENT

      *"----


      data: file_length type i,

      lines type i.

      data: filename like draw-filep,

      path like draw-filep.

      data: xfilecontent type xstring.

      data: lt_x_data like table of sdokcntbin.

      if fullfilename is supplied.

      find ':\' in fullfilename.

      if sy-subrc is not initial.

      concatenate 'C:\' fullfilename into fullfilename.

      endif.

      data: splitted type table of char255 with header line.

      split fullfilename at '.' into table splitted.

      describe table splitted.

      read table splitted index sy-tfill.

      if sy-subrc = 0.

      translate splitted to upper case.

      case splitted.

      when 'DOC'.

      dappl = 'WRD'.

      mimetype = 'application/msword'.

      when 'XLS'.

      dappl = 'XLS'.

      mimetype = 'application/vnd.ms-excel'.

      when 'PDF'.

      dappl = 'PDF'.

      mimetype = 'application/pdf'.

      when 'MPP'.

      dappl = 'MPP'.

      mimetype = 'application/vnd.ms-project'.

      when 'VSD'.

      dappl = 'VSD'.

      mimetype = 'application/vnd.ms-visio'.

      when 'PPT'.

      dappl = 'PPT'.

      mimetype = 'application/vnd.ms-powerpoint'.

      endcase.

      endif.

      endif.

      call function 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

      input = doknr

      IMPORTING

      output = doknr.

      data: pfx_exist.

      data: psx_draw like draw.

      call function 'CV200_DB_DOC_EXIST'

      EXPORTING

      pf_dokar = dokar

      pf_doknr = doknr

      pf_doktl = doktl

      pf_dokvr = dokvr

      IMPORTING

      pfx_exist = pfx_exist

      psx_draw = psx_draw.

      if pfx_exist is initial.

      raise NODOCUMENT.

      endif.

      xfilecontent = filecontent.

      file_length = xstrlen( xfilecontent ).

      call function 'SCMS_XSTRING_TO_BINARY'

      EXPORTING

      buffer = xfilecontent

      TABLES

      binary_tab = lt_x_data.

      describe table lt_x_data lines lines.

      data: pf_path type char255.

      pf_path = fullfilename.

      call function 'CV120_SPLIT_PATH'

      EXPORTING

      pf_path = pf_path

      IMPORTING

      pfx_path = filename

      pfx_file = path.

      data: ps_data type dms_rec_file.

      data: tbl_phio type dms_rec_phio.

      ps_data-lo_index = 1.

      ps_data-lo_key = 1.

      ps_data-dappl = dappl.

      tbl_phio-storage_cat = 'DMS_C1_ST'.

      tbl_phio-status = 'K1'.

      tbl_phio-lo_index = 1.

      tbl_phio-ph_index = 1.

      tbl_phio-active_version = 'X'.

      tbl_phio-delete_flag = 'X'.

      tbl_phio-default_langu = 'X'.

      tbl_phio-filename = fullfilename.

      tbl_phio-protected = 'X'.

      append tbl_phio to ps_data-tbl_phios.

      call function 'CV120_KPRO_MASTER_CREATE'

      CHANGING

      ps_data = ps_data.

      read table ps_data-tbl_phios index 1 into tbl_phio.

      data: ps_phio_id type sdokobject.

      ps_phio_id-class = 'DMS_PCD1'.

      ps_phio_id-objid = tbl_phio-ph_objid.

      data: it_dms_phf_cd1 type table of dms_phf_cd1 with header line.

      it_dms_phf_cd1-PHIO_ID = ps_phio_id-objid.

      it_dms_phf_cd1-FILE_NUM = 1.

      it_dms_phf_cd1-PH_CLASS = ps_phio_id-class.

      it_dms_phf_cd1-DOC_FORMAT = ''.

      it_dms_phf_cd1-DOC_FMTVER = 'PCHR'.

      it_dms_phf_cd1-MIMETYPE = mimetype.

      it_dms_phf_cd1-FILE_SIZE = file_length.

      it_dms_phf_cd1-FILE_NAME = filename.

      it_dms_phf_cd1-FILE_TYPE = 'B'.

      append it_dms_phf_cd1.

      insert DMS_PHF_CD1 from table it_dms_phf_cd1.

      data: access_info like table of scms_acinf with header line.

      access_info-comp_id = filename.

      access_info-comp_size = file_length.

      access_info-mimetype = mimetype.

      access_info-binary_flg = 'X'.

      access_info-first_line = 1.

      access_info-last_line = lines.

      append access_info.

      call function 'SCMS_R3DB_EXPORT'

      EXPORTING

      crep_id = 'DMS_C1'

      doc_id = ps_phio_id-objid

      TABLES

      access_info = access_info

      content_bin = lt_x_data.

      data: PTX_DRAT like table of drat,

      PTX_DRAZ like table of draz,

      PTX_DRAD like table of drad,

      PTX_FILES type DMS_TBL_FILE,

      PTX_DRAP like table of drap.

      CALL FUNCTION 'CV115_DOC_OPEN_CHANGE'

      EXPORTING

      PF_DOKAR = dokar

      PF_DOKNR = doknr

      PF_DOKTL = doktl

      PF_DOKVR = dokvr

      PF_READ_DRAT = 'X'

      PF_READ_DRAD = 'X'

      PF_READ_DRAP = 'X'

      PF_READ_COMP = 'X'

      PF_READ_KPRO = 'X'

      IMPORTING

      PSX_DRAW = psx_draw

      TABLES

      PTX_DRAT = PTX_DRAT

      PTX_DRAZ = PTX_DRAZ

      PTX_DRAD = PTX_DRAD

      PTX_FILES = PTX_FILES

      PTX_DRAP = PTX_DRAP.

      data: ptx_files_old like ptx_files.

      ptx_files_old = ptx_files.

      append ps_data to ptx_files.

      call function 'CV115_DOC_SAVE_BUFFER'

      EXPORTING

      pf_tacode = sy-tcode

      ps_draw = psx_draw

      ps_draw_old = psx_draw

      TABLES

      pt_drat = ptx_drat

      pt_drat_old = ptx_drat

      pt_drad = ptx_drad

      pt_drad_old = ptx_drad

      pt_drap = ptx_drap

      pt_draz = ptx_draz

      pt_kpro_data = ptx_files

      pt_kpro_data_old = ptx_files_old.

      call function 'CV111_DOC_SAVE'

      EXPORTING

      pf_commit = 'X'

      pf_update_task = 'X'.

      data: it_dms_ph_cd1 type table of dms_ph_cd1 with header line.

      select * from dms_ph_cd1 into table it_dms_ph_cd1

      where phio_id = ps_phio_id-objid.

      field-symbols: <fs> type dms_ph_cd1.

      loop at it_dms_ph_cd1 assigning <fs>.

      <fs>-chng_time = <fs>-crea_time.

      <fs>-chng_user = <fs>-crea_user.

      <fs>-state = 0002.

      endloop.

      update dms_ph_cd1 from table it_dms_ph_cd1.

      ENDFUNCTION.

      Edited by: abap 4 on Jun 19, 2008 11:14 AM

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.