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

Transform the code to Unicode

Former Member
0 Likes
941

Hi all,

I have the code converting TAB, CR and LF into spaces:

FIELD-SYMBOLS: <tb> TYPE x,

<tc> TYPE c.

DATA:

tab(6) TYPE x VALUE '09200D200A20',

char60(60) TYPE c.

CONCATENATE 'abCD' cl_abap_char_utilities=>horizontal_tab

cl_abap_char_utilities=>CR_LF '1234' INTO char60.

ASSIGN tab TO <tb> CASTING.

ASSIGN <tb> TO <tc> CASTING.

TRANSLATE char60 USING <tc>.

I was told that it would fail in Unicode system.

How to transform the code to make it work in Unicode?

Thanks in advance.

Best regards,

Eugene

7 REPLIES 7
Read only

Laxmana_Appana_
Active Contributor
0 Likes
859

Hi,

Go to program attributes and check unicode option and try.if system gives any error.then i think it won't work in unicode system.

Regards

Appana

Read only

abdul_hakim
Active Contributor
0 Likes
859

hi

you need to select the attribute Unicode in the Program Attribute.If it shows error then you need to replace the error statement with the correct syntax which will be supported in Unicode System..

For a list of valid Syntax in Unicode System Have look at the same in http://help.sap.com

Cheers,

Abdul Hakim

Read only

Clemenss
Active Contributor
0 Likes
859

Hi Eugene,

what about:

<pre>

REPLACE:

cl_abap_char_utilities=>horizontal_tab WITH ' '

INTO char60,

cl_abap_char_utilities=>CR_LF WITH ' '

INTO char60.

</pre>

Regards,

Clemens

Read only

Former Member
0 Likes
859

Hi Guys,

Thank you for your answers, but they don't help.

I know about checking the program for unicode and I went through help.sap.com, searched threads in forums. Still it's not clear for me.

The code of mine does work in non-unicode system.

I don't need to enhance it for non-unicode system.

I need to rewrite it to make it work in Unicode.

I suppose that I have to use some Unicode specific data types, probably the other ABAP statements etc.

How to do it?

I can use CL_ABAP_CONV_OUT_CE=>UCCP for returning Unicode codes, but in my case I always get 0030 (hex 23 == # as a replacement of invalid characters).

My main task: either to rewrite the code, or write another one which will replace hex codes 00 - 1F in Unicode system by spaces, for example.

Best regards,

Eugene

Message was edited by: Eugene Khusainov

Read only

0 Likes
859

Hi Eugene,

there are no Unicode specific data types. But unicode systems use (at least) 2 bytes to store one character, that means the internal representation of a single character is 2 bytes enabling you to store more than 255 different characters but thousands as required for Chinese and other languages.

I just tried

REPLACE cl_abap_char_utilities=>cr_lf WITH space INTO lv_string.

and it works perfect replacing Carriage Return and Line feed with a space character.

So I don't understand why this solution is not working for you - why is Replace not working?

Best regards,

Clemens

//

Read only

0 Likes
859

Hi Clemens,

Thank you for a reply.

It works. But it is very limited solution.

I'd prefer to use CL_ABAP_CHAR_UTILITIES=>GET_SIMPLE_SPACES_FOR_CUR_CP to get white-space chars in Unicode system. As I wrote, I need to replace ALL forbidden chars: hex 00 - 1F.

Best regards,

Eugene

Read only

sridhar_k1
Active Contributor
0 Likes
859

To replace TAB, CR, and LF change variable tab(6) to

tab(12) type x value '00090020000D0020000A0020' in your old code.

To replace all chars between 00-0F with space, try the following code. I don't have unicode system to test this.

data: len type i,

off type i,

hex(2) type x value '000F'. " '0F00' on windows app server

data char60(60) type c.

field-symbols <fs> type any.

concatenate 'abCD' cl_abap_char_utilities=>horizontal_tab

cl_abap_char_utilities=>cr_lf '1234' into char60.

len = strlen( char60 ).

while off lt len.

assign char60+off(1) to <fs> casting type x.

if <fs> le hex.

char60+off(1) = ' '.

endif.

add 1 to off.

endwhile.

write:/ char60.

Regards

Sridhar