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

Convert XSTRING to STRING conserving accented characters

Former Member
0 Likes
6,631

Hello,

I have an ITS application on an ECC 6.0 unicode system, which allows users to upload txt files.

In the associated ABAP program, I recuperate the content of this txt file in the form of XSTRING. I manage to convert without problem the XSTRING to a normal STRING, but I lose every accented characters (like é) in the process. I use class cl_abap_conv_in_ce to do the conversion, with encode parameter set to 'UTF-8'.

Do someone know if it is possible to do it properly and get all special characters ?

Thank you.

Thomas

6 REPLIES 6
Read only

Former Member
0 Likes
3,052

Hi,

Take a look at this code

DATA: file TYPE string VALUE `flights.dat`, 
      wa TYPE spfli. 

FIELD-SYMBOLS <hex_container> TYPE x. 

OPEN DATASET file FOR INPUT IN BINARY MODE. 

ASSIGN wa TO <hex_container> CASTING. 

DO. 
  READ DATASET file INTO <hex_container>. 
  IF sy-subrc = 0. 
    WRITE: / wa-carrid, 
             wa-connid, 
             wa-countryfr, 
             wa-cityfrom, 
             wa-cityto, 
             wa-fltime, 
             wa-distance. 
  ELSE. 
    EXIT. 
  ENDIF. 
ENDDO. 

CLOSE DATASET file.

Thanks

Ahsan

Read only

Former Member
0 Likes
3,052

Hello,

Can't do it like that. I receive the file as a table of raw data. Here is how it happens :

  • Get all data and concatenate converting to byte mode

LOOP AT lt_raw_data INTO ls_w3mime.

CONCATENATE lv_xstring ls_w3mime-line INTO lv_xstring IN BYTE MODE.

ENDLOOP.

  • Convert byte data to character data

TRY.

CALL METHOD cl_abap_conv_in_ce=>create

EXPORTING

encoding = 'UTF-8'

input = lv_xstring

RECEIVING

conv = lv_conv.

CATCH cx_parameter_invalid_range.

MESSAGE i059.

EXIT.

CATCH cx_sy_codepage_converter_init.

MESSAGE i059.

EXIT.

ENDTRY.

TRY.

CALL METHOD lv_conv->read

IMPORTING

data = lv_string.

CATCH cx_sy_conversion_codepage.

MESSAGE i059.

EXIT.

CATCH cx_sy_codepage_converter_init.

MESSAGE i059.

EXIT.

CATCH cx_parameter_invalid_type.

MESSAGE i059.

EXIT.

CATCH cx_parameter_invalid_range.

MESSAGE i059.

EXIT.

ENDTRY.

I have to start from my XSTRING.

Read only

Former Member
0 Likes
3,052

hi thomas,

there is a function module 'SCMS_STRING_TO_XSTRING'..

U can try this..

Read only

Former Member
0 Likes
3,052

I have to do it the other way around, convert XSTRING to STRING, and there are no equivalent of your function for this. All functions I found were doing the conversion in the same way I do.

Read only

Former Member
0 Likes
3,052

Thomas,

Suggest you to look for and try FM 'HR_KR_XSTRING_TO_STRING'

Alternatively you can also try using FM 'SCMS_XSTRING_TO_BINARY' to convert Xstring to Binary and then

use FM 'SCMS_BINARY_TO_STRING' to get the binary table converted to string.

Regards,

Damian

Read only

0 Likes
3,052

Hi,

I suggest to use methods of class CL_BCS_CONVERT for conversions, FMs like SCMS_XSTRING_TO_STRING are going to become obsolete.

Regards,

Ivan