on 08-01-2012 10:36 AM
Hi All,
I am facing a problem while uploading the document/file into the DMS ( Document Management System ) using WebDynPro.
I am able to upload Text File(.txt) successfully but for the other extensions like pdf/doc/etc are uploaded in DMS but with corrupted so not able to open.
Furthermore, I am using
file_contents: type xstring
file_type (i.e. mimetype): type string
file_name: type char255.
I am using below code for Uploading Document as well, layout's Screenshot is also attached for here for reference.
Please provide your valuable input the same .
Thanks,
Emon Master
METHOD onactiononupload .
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,
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'.
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. " lo_el_n_upload is not Initial.
ENDIF.
ENDMETHOD.
Thanks to all of you for spending your valuable time.
Issue has been solved by increase the length of line.
TYPES: BEGIN OF zst_ts_raw_line,
line(2550) type x,
END OF zst_ts_raw_line.
INSTEAD OF
TYPES: BEGIN OF zst_ts_raw_line,
line TYPE sdokcntbin,
END OF zst_ts_raw_line.
Please refer below link for further assistance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi-
I did the same but it is not working:
It attaches the file to server but it is not displaying .. it says correpted.
for TXT it works fine.
code:
TYPES : BEGIN OF zst_ts_raw_line,
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 ,
*ls_bindata type x255,"zst_ts_raw_line,
lt_bindata TYPE STANDARD TABLE OF zst_ts_raw_line," STANDARD TABLE
* lt_bindata type standard table of orblk," 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.
DATA lo_nd_upload TYPE REF TO if_wd_context_node.
DATA lo_el_upload TYPE REF TO if_wd_context_element.
lo_nd_n_file_download = wd_context->get_child_node( name =
wd_this->wdctx_node_view ).
* navigate from <CONTEXT> to <NODE_UPLOAD> via lead selection
lo_nd_node_upload = wd_context->get_child_node( name =
wd_this->wdctx_node_upload ).
* get element via lead selection
lo_el_node_upload = lo_nd_node_upload->get_element( ).
* @TODO handle not set lead selection
* get all declared attributes
lo_el_node_upload->get_static_attributes(
IMPORTING
static_attributes = ls_node_upload ).
CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
* in_xstring = ls_node_upload-file_contents
in_xstring = ls_node_upload-file_contents
IMPORTING
out_string = l_string.
ls_draw-dokar = 'DRW'.
ls_draw-dokvr = '00'.
ls_draw-doktl = '000'.
ls_draw-dwnam = sy-uname.
*ls_draw-dokst = 'CD'.
lv_storage_cat = 'YDMSTSTIX'.
*ls_api_ctrl-commit_flag = 'X'.
*ls_api_ctrl-save_flag = 'X'.
*ls_api_ctrl-api_mode = 'X'.
lv_documentnumber = 'SAMPLE_DOC1142'.
ls_draw-doknr = lv_documentnumber.
*ls_draw-sourcedatacarrier = 'DOCUMENTUM'.
ls_draw-doknr = lv_documentnumber.
* insert draw from ls_draw.
*endif.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = ls_node_upload-file_contents
*• 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.
CALL FUNCTION 'CV120_DOC_GET_APPL'
EXPORTING
*• PF_DIALOG =
*• PF_DISPLAY =
pf_file = '123.doc'
* PF_TYPDT =
IMPORTING
pfx_dappl = ls_files-dappl.
*•TABLES
*
*• PTX_TDWP =
ls_files-appnr = '1'.
ls_files-filename
= 'C:\Docu.........\123.doc'.
ls_files-updateflag = 'I'.
ls_files-langu = sy-langu.
ls_files-storage_cat = 'YDMSTSTIX'.
ls_files-description = 'Sample'.
*•ls_files-checked_in = 'X'.
*•ls_files-active_version = 'X'.
APPEND ls_files TO lt_files.
*•data : lv_dokar type DRAW-DOKAR,
*
*• lv_dokvr type DRAW-DOKVR,
*
*• lv_
* For Execute external Commit when using BAPIs
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
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_api_control = ls_api_ctrl
pf_content_provide = 'TBL'
IMPORTING
psx_message = ls_message
TABLES
pt_files_x = lt_files
pt_content = lt_drao.
COMMIT WORK.
Hi Emon,
Am facing the issue exactly what u have mentioned...
Infact i have changed the line size ( line(2550) type x, ).. Still i cant able to view the upload pdf and doc etc from DMS.
But am able to uplooad pdf and other stuff...
Kindly give me solution..how it is possible for you.. whether i need to change anything in the code or what??
Thanks
Murali
Hi Emon,
Try below code to upload document to DMS from webdynpro.
Here first I am uploading file into App Server and then storing into DMS. It works for all kind of files.
CONSTANTS path_name TYPE localfile VALUE '/usr/sap/tmp/'.
CONSTANTS log TYPE localfile VALUE '/usr/tmp/logFO.txt'.
* ---------------------------------------------------------------------* Create document* ---------------------------------------------------------------------
DATA : ls_documentdata TYPE bapi_doc_draw2.
DATA :ls_documentfiles TYPE bapi_doc_files2.
DATA: lt_documentfiles TYPE TABLE OF bapi_doc_files2.
DATA: lt_descr TYPE TABLE OF bapi_doc_drat.
DATA: lv_documentnumber TYPE bapi_doc_aux-docnumber,
gv_return TYPE bapiret2,
ls_file_list TYPE j_1i_str_exim_dms,
msg(80) TYPE c.
DATA: lv_apptyp(3) TYPE c.
DATA: file(255) TYPE c.
into file.
OPEN DATASET file FOR OUTPUT IN BINARY MODE MESSAGE msg.
TRANSFER content TO file. "content is the XSTRING format of file
CLOSE DATASET file.
CALL FUNCTION 'SPLIT_FILENAME'
EXPORTING
long_filename = file
IMPORTING
*PURE_FILENAME =
pure_extension = lv_apptyp.
TRANSLATE lv_apptyp TO UPPER CASE.
ls_documentdata-documenttype = 'DMO'.
ls_documentdata-documentversion = '00'.
ls_documentdata-documentpart = '000'.
ls_documentdata-description = 'Test Document'.
ls_documentdata-laboratory = '001'.
ls_documentdata-wsapplication1 = lv_apptyp.
ls_documentdata-docfile1 = file.
ls_documentdata-savedocfile1 = file.
ls_documentdata-docfile1 = file.
ls_documentdata-savedocfile1 = file.
ls_documentfiles-documenttype = 'DMO'.
ls_documentfiles-documentpart = '000'.
ls_documentfiles-documentversion = '00'.
ls_documentfiles-storagecategory = 'DMS_C1_ST'.
ls_documentfiles-wsapplication = lv_apptyp.
ls_documentfiles-docpath = path_name.
ls_documentfiles-docfile = filename.
ls_documentfiles-description = iv_description.
ls_documentfiles-language = 'EN'.
ls_documentfiles-checkedin = 'X'.
APPEND ls_documentfiles TO lt_documentfiles .
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING
documentdata = ls_documentdata
hostname = 'content-srv'
pf_http_dest = 'SAPHTTPA'
pf_ftp_dest = 'SAPFTPA'
IMPORTING
documentnumber = Ev_documentnumber
return = EV_MESSAGE
TABLES
documentdescriptions = lt_descr
documentfiles = lt_documentfiles.
COMMIT WORK.
Thanks & Regards,
Venkat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Emon,
I had a same kind of requirement this is how i did it, Please check if it is of any use to you.
method Load_documents.
call function 'CVAPI_DOC_GETDETAIL'
exporting
pf_dokar = i_document_type
pf_doknr = i_document_number
pf_dokvr = i_document_version
pf_doktl = i_document_part
pf_active_files = 'X' " bring only active files
tables
pt_files = lt_files
exceptions
not_found = 1
no_auth = 2
error = 3
others = 4.
if sy-subrc eq 0 and
lt_files is not initial.
loop at lt_files into l_file.
clear: lt_req_file.
" Get the extension of the file
find first occurrence of regex '\.[^\.]+$' in l_file-filename match offset l_dot_offset.
add 1 to l_dot_offset.
" Get the name of the file
find all occurrences of regex '[^\\]*(\.).{3,4}' in l_file-filename results lt_result_tab.
" Get the last match
describe table lt_result_tab lines sy-index.
read table lt_result_tab into l_result index sy-index.
if sy-subrc eq 0.
" File name
l_original-file_name = l_file-filename+l_result-offset(l_result-length).
endif.
l_message-type = 'I'.
concatenate 'Processing file' l_original-file_name
into l_message-message separated by space.
append l_message to _messages.
append l_file to lt_req_file.
if i_with_content eq 'X'.
clear: l_bin_content,
l_content,
lt_content.
refresh: lt_xdata.
call function 'CVAPI_DOC_CHECKOUTVIEW'
exporting
pf_dokar = i_document_type
pf_doknr = i_document_number
pf_dokvr = i_document_version
pf_doktl = i_document_part
pf_content_provide = 'TBL'
tables
pt_files = lt_req_file
ptx_content = lt_content.
if lt_content is not initial.
loop at lt_content into l_content.
if lt_xdata is initial.
perform doc_get_mime_type in program saplcom_cfg_db_tools
using l_content-orblk
changing l_original-mime_type.
endif.
ls_xdata-line = l_content-orblk.
append ls_xdata to lt_xdata.
if lf_size is initial.
lf_size = l_content-orln.
endif.
endloop.
" Convert binary to xstring
call function 'SCMS_BINARY_TO_XSTRING'
exporting
input_length = lf_size
importing
buffer = l_bin_content
tables
binary_tab = lt_xdata
exceptions
failed = 1
others = 2.
clear: lf_size.
else.
l_message-type = 'E'.
l_message-message = 'File load failed'.
append l_message to _messages.
endif.
endif.
l_original-file_content = l_bin_content.
append l_original to et_originals.
endloop.
endmethod.
method publish.
call method me->load_documents
exporting
i_document_type = i_document_type
i_document_number = i_document_number
i_document_version = i_document_version
i_document_part = i_document_part
i_with_content = 'X'
importing
et_originals = lt_originals
et_char_values = lt_char_values.
if lt_originals is not initial.
create object l_km_ws_obj.
loop at lt_originals into l_original.
l_document_input-content-content = l_original-file_content.
loop at lt_directories into l_directory.
l_document_input-parent_collection_rid = l_directory-directory.
l_message-type = 'I'.
concatenate 'KM full path is ' l_document_input-parent_collection_rid
into l_message-message separated by space.
append l_message to _messages.
l_length = strlen( l_document_input-parent_collection_rid ).
l_length = l_length - 1.
l_document_input-parent_collection_rid = l_document_input-parent_collection_rid(l_length).
l_document_input-child_name = l_original-file_name.
l_document_input-content-metadata-length = xstrlen( l_document_input-content-content ).
l_document_input-overwrite_enforced = 'X'.
l_km_ws_obj->create_document( exporting input = l_document_input
importing output = l_document_output ).
l_message-type = 'I'.
concatenate 'File' l_document_input-child_name 'has been created'
into l_message-message separated by space.
append l_message to _messages.
endloop.
endloop.
else.
l_message-type = 'I'.
concatenate 'Document was not classified with relevant directory category ' l_char_value-value
into l_message-message separated by space.
append l_message to _messages.
endif.
end method.
Thanks
Phani
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.