‎2010 Aug 02 2:29 PM
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
‎2010 Aug 04 8:35 AM
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).
‎2010 Aug 02 2:49 PM
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
‎2010 Aug 02 5:12 PM
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
‎2010 Aug 04 8:35 AM
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).
‎2010 Aug 04 9:00 AM
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
‎2010 Aug 04 9:41 AM
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)