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

Replace 0 (zero) bytes in strings

Former Member
0 Likes
1,694

Hi there,

we are transfering column data to an external system (C programm) -

some of the data in SAP contain zero bytes (not the character '0') in hex view 00 00.

But C strings are null delimited.

My question:

How can I replace all occurences of hex .. 00 00 .. in a string with another valid character (e.g. space 20 00)?

There must be a way to replace single bytes in a char variable.

Thanks,

Andi

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,174

You should also determine why you have these 00 bytes, and why your C program can't handle them, because maybe you shouldn't simply delete them.

For example, if you have a Unicode SAP system, all occidental characters are encoded on 2 bytes with one which is 00, but some other characters may contain 2 non 00 bytes. In that case, you may get some bizarre characters in your C program because it will be unable to understand in which code page they are encoded.

In that case, you should better do as Keshav said: determine what encoding your C program expects, and then, in your ABAP program, convert your string from SAP code page (name of encoding schemes in SAP) to this encoding. You also indicate a replacement character for those characters which don't have a corresponding value.

Notes:

1) if you write data to a file (on server probably), you can choose the target code page and replacement character in OPEN DATASET statement

2) if you use RFC, you can enter the replacement character directly in the RFC destination (SM59).

5 REPLIES 5
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,174

You can try moving the string to a xstring variable and try replacing it in byte mode.

make use of classes cl_abap_conv_out_ce and cl_abap_conv_in_ce.

Please search in scn for this classes, you will get lot of examples.

here is an example link:[http://www.sapfans.com/forums/viewtopic.php?p=91589&sid=c7ef36fec60a616f1194b6fdac217d4b]

Edited by: Keshav.T on Aug 2, 2010 7:20 PM

Read only

luis_quispe
Explorer
0 Likes
1,174

Hi,

In this case do you use the clase cl_abap_char_utilities, for replace Cero by atribute SPACE_STR_LANGU or SPACE_STR.

regards

Lquispe

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,176

You should also determine why you have these 00 bytes, and why your C program can't handle them, because maybe you shouldn't simply delete them.

For example, if you have a Unicode SAP system, all occidental characters are encoded on 2 bytes with one which is 00, but some other characters may contain 2 non 00 bytes. In that case, you may get some bizarre characters in your C program because it will be unable to understand in which code page they are encoded.

In that case, you should better do as Keshav said: determine what encoding your C program expects, and then, in your ABAP program, convert your string from SAP code page (name of encoding schemes in SAP) to this encoding. You also indicate a replacement character for those characters which don't have a corresponding value.

Notes:

1) if you write data to a file (on server probably), you can choose the target code page and replacement character in OPEN DATASET statement

2) if you use RFC, you can enter the replacement character directly in the RFC destination (SM59).

Read only

0 Likes
1,174

Hi Sandra,

thank you for your post and tipps.

I know how Unicode characters are encoded.

The source SAP System is a ANSI system - so we do not have any multibyte encodings.

It seems that that data came from a migration from R2 to R3.

Thanks,

Andi

Read only

0 Likes
1,174

Okay. So, it will be easier to use this code:


DATA l_null_character TYPE c LENGTH 1.
l_null_character = cl_abap_conv_in_ce=>uccpi( 0 ).
REPLACE ALL OCCURRENCES OF l_null_character WITH space IN yourstring.

Edited by: Sandra Rossi on Aug 4, 2010 8:03 PM

(I forgot ALL OCCURRENCES OF in my initial post)