‎2006 Jul 12 11:34 AM
Hello,
i read a utf-16 file. The read text is diplayed like this string:
yp<#?#x#m#l# #v#e#r#s#i#o#n#=#"#1#.#0#"
How can I convert the text? I haven't found functions to do that.
‎2006 Jul 12 11:54 AM
Hi,
Check this :
/people/ulrich.brink/blog/2005/08/18/unicode-file-handling-in-abap
It may help.....
Regards
Appana
‎2006 Jul 12 11:41 AM
When you open the dataset, use the encoding option.
open dataset dsn in input mode encoding 'utf-16'.
Regards,
ravi
‎2006 Jul 12 11:50 AM
‎2006 Jul 12 11:54 AM
Hi,
Check this :
/people/ulrich.brink/blog/2005/08/18/unicode-file-handling-in-abap
It may help.....
Regards
Appana
‎2006 Jul 12 2:11 PM
Thanks Appana, cl_abap_conv_in_ce seems to be the right class - but i can't get it to work. - To use it in combination with OPEN DATASET.
Unfortunately, the OPEN DATASET statement does not support UTF-16.
‎2006 Jul 12 10:33 PM
Here's a QDAC (Quick & Dirty ABAP code) to convert UTF-16 file on app server to sap default codepage file.
Tested on a non-unicode 640 system.
data: gt_line type string occurs 0 with header line,
gv_bin type xstring,
conv_obj type ref to cl_abap_conv_in_ce.
parameters: in_file type rlgrap-filename,
out_file type rlgrap-filename.
start-of-selection.
check not in_file is initial.
open dataset in_file for input in binary mode.
do.
read dataset in_file into gv_bin.
if sy-subrc ne 0.
close dataset in_file.
exit.
endif.
if sy-index eq 1.
perform create_conv_obj.
endif.
try.
call method conv_obj->convert
exporting
input = gv_bin
n = -1
importing
data = gt_line.
catch cx_sy_conversion_codepage .
catch cx_sy_codepage_converter_init .
catch cx_parameter_invalid_type .
endtry.
append gt_line.
enddo.
check not out_file is initial.
open dataset out_file for output in binary mode.
loop at gt_line.
transfer gt_line to out_file.
endloop.
close dataset out_file.
*&--------------------------------------------------------------------*
*& Form create_conv_obj
*&--------------------------------------------------------------------*
form create_conv_obj.
data: lv_bom(2) type x,
lv_encoding type abap_encod,
lv_endian type abap_endia.
lv_bom = gv_bin.
if lv_bom eq 'FFFE'.
lv_encoding = '4103'. "code page for UTF-16LE
lv_endian = 'L'.
shift gv_bin left by 2 places in byte mode.
elseif lv_bom eq 'FEFF'.
lv_encoding = '4102'. "code page for UTF-16BE
lv_endian = 'B'.
shift gv_bin left by 2 places in byte mode.
else.
message 'Byte order mark not found at the begining of the file'
type 'E'.
endif.
try.
call method cl_abap_conv_in_ce=>create
exporting
encoding = lv_encoding
endian = lv_endian
replacement = '#'
receiving
conv = conv_obj.
catch cx_parameter_invalid_range .
catch cx_sy_codepage_converter_init .
endtry.
endform. "create_conv_objRegards
Sridhar
‎2006 Jul 18 8:04 AM
I got it. There is a bug in the sap method to create a table of an xml object. The function makes intern a wrong unicode conversion. You have to use the function SO_SOLIXTAB_TO_SOLITAB after using cl_xml_document->get_as_table to get a right conversion on a unicode system.