on 09-21-2010 9:26 AM
Hi Experts ,
I want to achieve following functionality in WD ABAP.
User should be able to upload and download any file ( in any fromat ) , to / form document management server.
Since user can upload / download any file so I am using a file download UI , which would open any file in a new window.
I have searched about this in SDN ([ link |https://wiki.sdn.sap.com/wiki/display/Snippets/WDA%20Retrieve%20Data%20from%20DMS%20server]) and I have created a FM which gives me Xstring corresponding to the file in the DMS system.
then I pass this Xstring data to my context 'DATACONTENT' which is bound to file download UI (data property). But When I execute this application I am getting junk data in the new window. Please correct me where I am making a mistake.
following is the code in FM which in turn passes v_xstring ( of type xstring ) to WD ABAP . Then I bind this value to context
'DATACONTENT'.
wd_context->set_attribute( name = 'DATACONTENT' value = V_XSTRING ).
FUNCTION ZTESTING_EP.
*"----
""Local Interface:
*" IMPORTING
*" VALUE(DOCUMENTTYPE) LIKE BAPI_DOC_AUX-DOCTYPE DEFAULT 'IVF'
*" VALUE(DOCUMENTNUMBER) LIKE BAPI_DOC_AUX-DOCNUMBER DEFAULT 1
*" VALUE(DOCUMENTPART) LIKE BAPI_DOC_AUX-DOCPART DEFAULT 000
*" VALUE(DOCUMENTVERSION) LIKE BAPI_DOC_AUX-DOCVERSION DEFAULT 00
*" EXPORTING
*" VALUE(C) LIKE BAPIEMPLB-RETURN
*" VALUE(V_XSTRING) TYPE XSTRING
*" VALUE(RETURN) TYPE BAPIRET2
*"----
data: ls_docfiles type bapi_doc_files2,
ls_dms type dms_doc_files,
lt_docfiles type standard table of bapi_doc_files2.
select single * from dms_doc_files
into ls_dms
where "Retrieve file
MOVE '0000000000000000000000001' to DOCUMENTNUMBER .
MOVE '000' to DOCUMENTPART .
MOVE '00' to DOCUMENTVERSION .
if sy-subrc = 0.
ls_docfiles-documenttype = DOCUMENTTYPE.
ls_docfiles-documentnumber = DOCUMENTNUMBER .
ls_docfiles-documentpart = DOCUMENTPART .
ls_docfiles-documentversion = DOCUMENTVERSION.
endif.
call function 'BAPI_DOCUMENT_CHECKOUTVIEW2'
exporting
documenttype = ls_docfiles-documenttype
documentnumber = ls_docfiles-documentnumber
documentpart = ls_docfiles-documentpart
documentversion = ls_docfiles-documentversion
documentfile = ls_docfiles
getstructure = '1'
getcomponents = 'X'
getheader = 'X'
pf_ftp_dest = 'SAPFTPA'
IMPORTING
return = return
tables
documentfiles = lt_docfiles.
MOVE return to return.
data: i_bin type standard table of sdokcntbin,
i_info type standard table of scms_acinf,
v_info type scms_acinf,
v_id type sdok_phid,
v_cat type sdok_stcat.
if sy-subrc = 0.
loop at lt_docfiles into ls_docfiles.
v_id = ls_docfiles-docfile.
v_cat = ls_docfiles-storagecategory.
call function 'SCMS_DOC_READ'
exporting
stor_cat = v_cat
doc_id = v_id
phio_id = ls_docfiles-file_id
tables
access_info = i_info
content_bin = i_bin
exceptions
bad_storage_type = 1
bad_request = 2
unauthorized = 3
comp_not_found = 4
not_found = 5
forbidden = 6
conflict = 7
internal_server_error = 8
error_http = 9
error_signature = 10
error_config = 11
error_format = 12
error_parameter = 13
error = 14
others = 15
.
endloop.
if sy-subrc <> 0.
else.
data: v_xstring type xstring.
read table i_info into v_info index 1.
call function 'SCMS_BINARY_TO_XSTRING'
exporting
input_length = v_info-comp_size
importing
buffer = v_xstring
tables
binary_tab = i_bin
exceptions
failed = 1
others = 2
.
if sy-subrc <> 0.
endif.
endif.
endif.
ENDFUNCTION.
Thanks in advance
Abhay
Hi,
I cant find this function 'CVAPI_DOC_GETDETAIL' as you have specified here to use to set the details.
Kindly can you guide me what is the other way to donwload files from mime?
Thanks and Regards
Tenzin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Madhu ,
Thanks for a quick reply .
I dont have to use CL_WD_RUNTIME_SERVICES to download the file as I just want to open the file in a new window. I had to pass Xstring , mimetype and filename from the i_info table ( in the FM SCMS_DOC_READ). Then I passed the missing values of mimetype and filename into the contexts.
Now the DMS files are opening fine.
Thanks
Abhay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Abhay,
I have used the belwo method to achive the same:
1) Call funtion 'CVAPI_DOC_GETDETAIL' to get the document details.This function module returns PT_FILES tables parameter
2) Loop at PT_FILES and call the 'CV120_GET_MIME_TYPE' funtion by passing DAPPL of PT_FILES to get the mime type.
3)call function 'CVAPI_DOC_CHECKOUTVIEW' by passing PT_FILES values form above retrived to the function module in this step
4)Loop at the content and convert to XSTRING using SCMS_XSTRING_TO_BINARY
After getting the XSTRING,MIMETYPE use ATTACH_FILE_FOR_RESPONSE method of CL_WD_RUNTIME_SERVICES to download the file
Sample Code:
CALL FUNCTION 'CVAPI_DOC_GETDETAIL'
EXPORTING
pf_dokar = ls_draw-dokar
pf_doknr = iv_documentnumber
pf_dokvr = ls_draw-dokvr
pf_doktl = ls_draw-doktl
pf_read_drat = abap_true
IMPORTING
psx_draw = ls_draw
TABLES
pt_drat = et_drat
pt_files = et_files
EXCEPTIONS
not_found = 1
no_auth = 2
error = 3
OTHERS = 4.
ENDIF.
IF et_files IS NOT INITIAL.
LOOP AT et_files INTO ls_files.
CALL FUNCTION 'CV120_GET_MIME_TYPE'
EXPORTING
pf_dappl = ls_files-dappl
* PF_FILE =
IMPORTING
pfx_mimetype = lv_mimetype.
CLEAR lt_files_checkout.
CLEAR lt_content.
ls_files_checkout-description = ls_files-description.
ls_files_checkout-lo_objid = ls_files-lo_objid.
ls_files_checkout-ph_objid = ls_files-ph_objid.
APPEND ls_files_checkout TO lt_files_checkout.
CALL FUNCTION 'CVAPI_DOC_CHECKOUTVIEW'
EXPORTING
pf_dokar = ls_draw-dokar
pf_doknr = iv_documentnumber
pf_dokvr = ls_draw-dokvr
pf_doktl = ls_draw-doktl
pf_content_provide = gc_content_provide
* PS_API_CONTROL =
* PF_STD_URL = 'X'
IMPORTING
psx_message = ls_message
psx_draw = ls_draw
TABLES
pt_files = lt_files_checkout
* PTX_COMPONENTS =
ptx_content = lt_content.
IF ls_message CA gc_error_a.
ev_fail = abap_true.
ELSE.
CLEAR lt_xdata.
CLEAR ls_bindata.
*Data into String
LOOP AT lt_content INTO ls_content.
lv_size = ls_content-orln.
ls_xdata-line = ls_content-orblk.
APPEND ls_xdata TO lt_xdata.
ENDLOOP.
* -- Convert XData to Xstring
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = lv_size
IMPORTING
buffer = ls_bindata
TABLES
binary_tab = lt_xdata
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc NE 0.
ev_fail = abap_true.
ELSE.
ls_file_list-filename = ls_files-description.
ls_file_list-mimetype = lv_mimetype.
ls_file_list-content = ls_bindata.
ls_file_list-application_id = ls_files-lo_objid.
ls_file_list-file_id = ls_files-ph_objid.
APPEND ls_file_list TO et_file_list.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
Regards,
Madhu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.