Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

German Special Characters in XSTRING to STRING conversion

0 Likes
1,888

Hi Experts,

I have a CSV file (created from a Windows Excel file) with German Special Characters (e.g. 'ä', 'Ä') and I am trying to read this into ABAP internal tables. By using the THTMLB tag 'thtmlb:fileUpload' I get an XSTRING and I am trying to convert this into STRING. However, wheny trying to do this I get an exception 'CX_SY_CONVERSION_CODEPAGE'.

This is my coding:

data: conv type ref to cl_abap_conv_in_ce.

conv = cl_abap_conv_in_ce=>create( input = lr_upload->file_content ).

conv->read( importing data = lv_content ).

Note: lr_upload is my XSTRING object from the file upload, lv_content is a STRING.

In the CSV file the German special characters look fine and the SAP system is a Unicode system, but it seems like there are some problems with the conversions somehow. Any ideas from the experts?

Thanks a lot and Regards,

Jens

Hi Experts,

I have a CSV file (created from a Windows Excel file) with German Special Characters (e.g. 'ä', 'Ä') and I am trying to read this into ABAP internal tables. By using the THTMLB tag 'thtmlb:fileUpload' I get an XSTRING and I am trying to convert this into STRING. However, wheny trying to do this I get an exception 'CX_SY_CONVERSION_CODEPAGE'.

This is my coding:

data: conv type ref to cl_abap_conv_in_ce.

conv = cl_abap_conv_in_ce=>create( input = lr_upload->file_content ).

conv->read( importing data = lv_content ).

Note: lr_upload is my XSTRING object from the file upload, lv_content is a STRING.

In the CSV file the German special characters look fine and the SAP system is a Unicode system, but it seems like there are some problems with the conversions somehow. Any ideas from the experts?

Thanks a lot and Regards,

Jens

3 REPLIES 3
Read only

andreas_mann3
Active Contributor
0 Likes
1,297

look f1 to open and try something like this:


 open dataset file for input in text mode encoding non-unicode.

grx

Andreas

Read only

0 Likes
1,297

Hi Andreas,

thanks a lot for your help but I am not sure if this would work for me. The data I get from the file upload object is an XSTRING and apparently the dataset 'file' cannot be an x type.

I also found another way to convert XSTRING to STRING:

  • convert content to internal table...

call function 'CRM_IC_XML_XSTRING2STRING'

exporting

inxstring = lr_upload->file_content

importing

outstring = lv_content.

This yields no exception but the German special characters are translated into '?' (instead of 'ö') in the string lv_content.

Maybe any other ideas?

Thanks,

Jens

Read only

Former Member
0 Likes
1,297

As you mention a csv file I'm wondering if your encoding is wrong: I.e. when you create your instance of cl_abap_conv_in_ce you don't specify the encoding of your source hex string, so that means the default encoding is used, which should be UTF-8 in your case. So if your csv file is not encoded in UTF-8, specify the correct encoding in the create method and see if that helps.

Depending on how you get the file contents you might actually be able to combine the file retrieval with the conversion in one step. E.g. if the file is read from the application server you could specify the used code page via [open dataset ... in legacy text mode ... code page|http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_MODE.htm#&ABAP_ALTERNATIVE_4@4@]. Similarly method gui_upload of class cl_gui_frontend_services also allows you to specify a code page.

If all of this doesn't help, post some further details on your file (e.g. sample content & encoding) and possibly add some further details from the exception you're getting. As you mention a Unicode system it basically means that we should be able to convert all characters without any problem as long as we specify the correct source code page.

Cheers, harald