2011 Aug 19 4:26 AM
Hi,
I am trying to download (local) the data in binary format to XML using CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD. But the data that has been downloaded contains all chinese characters instead of the actual data. And this doesn't happen everytime I download the file, but very sporadic. I am guessing this is something to do with the code pade. I have tried using different code pages and couldn't resolve the issue. we are on 4.7 and it is non-unicode.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING
BIN_FILESIZE = L_LEN
FILETYPE = 'BIN'
FILENAME = 'C:/XML/Test.xml'
CODEPAGE = '4110'
CHANGING
DATA_TAB = LT_DATA
Please advise.
2011 Aug 24 4:53 PM
Hi Tony,
you might want to check out interface IF_IXML and class CL_IXML_80_20 for conversions before download.
example:
form xstring_download using p_xml_xstring type xstring.
data: lt_filename type standard table of file_table with header line.
data: lv_rc type i. " Anzahl der Dateien := 1.
* Deklarationen für DOWNload...
data: lv_download_rc type sysubrc.
data: lv_filename type string.
types: lty_x_line(256) type x,
lty_x_tab type table of lty_x_line.
data:
lr_ixml type ref to if_ixml,
lr_document type ref to if_ixml_document,
lr_streamfactory type ref to if_ixml_stream_factory,
lr_parser type ref to if_ixml_parser,
lr_istream type ref to if_ixml_istream,
lv_xtab_size type i,
lt_xtab type lty_x_tab.
*** STEP 1
*** transform XML String of type XSTRING into Table
* create the ixml main factory
lr_ixml = cl_ixml=>create( ).
* create a stream factory
lr_streamfactory = lr_ixml->create_stream_factory( ).
* create a input stream
lr_istream =
lr_streamfactory->create_istream_xstring( string = p_xml_xstring ).
* create a ixml document (DOM Respresentation)
lr_document = lr_ixml->create_document( ).
* create a xml parser
lr_parser = lr_ixml->create_parser(
document = lr_document
stream_factory = lr_streamfactory
istream = lr_istream ).
* parse document
check lr_parser->parse( ) = 0.
* render to table of x -> default encoding utf-8
call method cl_ixml_80_20=>render_to_table_of_x "also: table_of_c
exporting
document = lr_document
pretty_print = 1
importing
stream_table = lt_xtab
stream_table_size = lv_xtab_size.
*** Step 2
*** Download
* Init
clear lv_rc.
refresh lt_filename.
lv_download_rc = 4.
while lv_download_rc ne 0.
call method cl_gui_frontend_services=>file_open_dialog
changing
file_table = lt_filename[]
rc = lv_rc
exceptions
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
others = 5.
if sy-subrc <> 0.
* MESSAGE annn(kkkk) WITH space. "<<<<<< adjust
elseif lv_rc lt 1. "e.g. abort by user
exit. "from while loop.
endif.
if not lt_filename[] is initial.
read table lt_filename index 1.
move lt_filename-filename to lv_filename. "implicit conversion
call function 'GUI_DOWNLOAD'
exporting
bin_filesize = lv_xtab_size
filename = lv_filename
filetype = 'BIN'
tables
data_tab = lt_xtab
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
if sy-subrc <> 0.
* MESSAGE innn(kkkk) WITH g_filename. <<<<<< adjust
* GUI-Übertragungsfehler (UPLOAD &1)
else.
lv_download_rc = 0.
endif.
endif. "not lt_filename[] is initial.
endwhile.
endform . "xstring_download
have fun!
hp
2015 Feb 24 7:50 AM
Thanks Holger,
this helped me a lot. Great work.... Very often you read the advice to download the content in ASC-format which will probably causes trouble using an extended charset in ABAP.
Again, thank you.
Hendrik