on 05-27-2011 7:43 AM
Hi Experts,
I am trying to download a file through Web Dynpro file download UI element..The file is stored in application server in binary format ..in my code i am reading the file in binary mode,converting Binary File into Xstring(Using FM SCMS_BINARY_TO_XSTRING) ..getting its Mime type and binding the UI element properties (data with XString, Mime type and file name) with respective context attributes..But the problem is file is getting opened but Junk data is getting displayed on it..Not sure where i am making the mistake.
Please post your code here. I can't see any mistake considering the approach you use.
regards, Lukas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Lukas,thanks for the reply..please find the code
here '/tmp/accenturedocs' is the folder name on application server,and zdocs_list_tab is the table that contains file URL.File upload is on the BSP page (custom logic to upload the file ) where they are storing local file path in ztable.Same i am extracting in my code to get File URL.
DATA: i_file TYPE rlgrap-filename .
DATA:v_path TYPE zlist.
DATA:i_datatab TYPE STANDARD TABLE OF tbl1024,
wa_datatab TYPE tbl1024.
DATA file TYPE string.
DATA dot_offset TYPE i.
DATA extension TYPE mimetypes-extension.
DATA mimetype TYPE mimetypes-type.
SELECT SINGLE description
FROM zdocs_list_tab
INTO v_path.
CONCATENATE '/tmp/accenturedocs' v_path INTO i_file.
FIELD-SYMBOLS <hex_container> TYPE x.
OPEN DATASET i_file FOR INPUT IN LEGACY BINARY MODE.
IF sy-subrc NE 0.
MESSAGE e999(00) WITH 'Error opening file' .
ENDIF.
ASSIGN wa_datatab TO <hex_container> CASTING.
DO.
READ DATASET i_file INTO <hex_container>.
IF sy-subrc = 0.
APPEND wa_datatab TO i_datatab.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET i_file.
DATA:l_count TYPE i,
l_len TYPE i.
DESCRIBE TABLE i_datatab LINES l_count.
READ TABLE i_datatab INTO wa_datatab INDEX l_count.
l_len = XSTRLEN( wa_datatab-line ).
l_len = l_len + ( l_count - 1 ) * 1022.
DATA: v_xstring TYPE xstring.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = l_len
IMPORTING
buffer = v_xstring
TABLES
binary_tab = i_datatab
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
file = i_file.
" Find out file name extension
FIND FIRST OCCURRENCE OF REGEX '\.[^\.]+$' IN file MATCH OFFSET
dot_offset.
ADD 1 TO dot_offset.
extension = file+dot_offset.
" Get mime type
CALL FUNCTION 'SDOK_MIMETYPE_GET'
EXPORTING
extension = extension
IMPORTING
mimetype = mimetype.
DATA lv_file_content TYPE wd_this->element_context-file_content.
get element via lead selection
lo_el_context = wd_context->get_element( ).
set single attribute
lo_el_context->set_attribute(
name = `FILE_CONTENT`
value = v_xstring ).
same way i am assigning file name and file mime type to context attributes.
please suggest where is the mistake.
Hi,
I kind of don't understand your approach here:
CONCATENATE '/tmp/accenturedocs' v_path INTO i_file.
FIELD-SYMBOLS <hex_container> TYPE x.
OPEN DATASET i_file FOR INPUT IN LEGACY BINARY MODE.
IF sy-subrc NE 0.
MESSAGE e999(00) WITH 'Error opening file' .
ENDIF.
ASSIGN wa_datatab TO <hex_container> CASTING.
DO.
READ DATASET i_file INTO <hex_container>.
IF sy-subrc = 0.
APPEND wa_datatab TO i_datatab.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET i_file.
DATA:l_count TYPE i,
l_len TYPE i.
DESCRIBE TABLE i_datatab LINES l_count.
READ TABLE i_datatab INTO wa_datatab INDEX l_count.
l_len = XSTRLEN( wa_datatab-line ).
l_len = l_len + ( l_count - 1 ) * 1022.
DATA: v_xstring TYPE xstring.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = l_len
IMPORTING
buffer = v_xstring
TABLES
binary_tab = i_datatab
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc 0.
ENDIF.
In my opinion you should read a binary file from appserver no different from this:
DATA: lv_xstring TYPE xstring.
OPEN DATASET i_file FOR INPUT IN BINARY MODE.
READ i_file INTO lv_xstring.
CLOSE DATASET i_file.
I wager I missunderstand something of your requirement, because there must be a reason why you do it as complicated as, well, you do ;-). Why can't you use an xstring from the beginning instead of reading it in BYTE mode into a casted X field-symbol and then eventually concatenating it into xstring with a FM?
best regards, Lukas
Hi Lukas,
when i read the file through Read Data set..i am using Do ..End do loop to read each record one at a time and putting it into table i_datatab..so finally the table i_datatab contains 37 entries.Finally i am getting one single Xstring for whole internal binary table.f i go by your approach then i will read the binary file only once,only first record.then what will happen to the rest of file content.
If you use your appraoch you end up being where my approach starts. I'm confused now 😄
You have ONE file, right? Why does it matter whether you read it piece by piece or as a whole entity. It's all binary in the end. Have you tried doing it with xstring from the start and ended up having an incomplete file or did you use your approcha as it is at the moment from the start?
regards, Lukas
Hi Lukas,
You are correct..I tried that also but it did not work..i have a feeling that the approach i am using for file download is incorrect..As for the first time i am working on webdynpro abap. Its an SRM based project and File upload is on the BSP page...Same uploaded file we have to download on the Webdynpro page..There was a existing standard functionality for file upload on BSP ..i debug that and found out that the uploaded file is getting stored in BDS..since BDS was a quite new thing for me ..i decided to go by uploading the files in application server.But somehow its not working and i am in dilemma should i go by uploading the document in BDS and then downloading them???i know i am confusing you but i am confused as well..:D
Sonika
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.