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 all space with ~ in xstring format.

Former Member
0 Likes
2,753

Hi Experts,

I am reading an XML file into a XSTRING variable and parsing the XSTRING to retrieve the data into Internal table.

What i want-

I want to replace all occurances of space in the file with some recognizable character ( say ~ ).

This i need to do once the file is read into XSTRING variable, in this xstring variable i want to replace all spaces with other character's value.

Is it feasible to replace like this in XSTRING variable for space?

In XSTRING , a space is stored '0D0A'

and i know 'replace all occurrences' works for Char type data object.

How to go about this?

Any help or clue is highly appreciated.

Regards,

3 REPLIES 3
Read only

Former Member
0 Likes
1,199

I think your idea works.

Just am not sure how you refer to the Hexadecimal Codes. I do by a 2 bytes character, for instance - A is coded like 41. Space for me is 20, not 0DA0.

Try the following example.

DATA: x TYPE xstring,
      y TYPE  string.

x = '4156524148414D'. "AVRAHAM's literal hexadecimal coding
x = '4120562052204120482041204D'. "A V R A H A M
y = x.
REPLACE ALL OCCURRENCES OF '20' IN y WITH '78'. "requires a character type input paramater, can't pass XSTRING.
x = y.

CALL FUNCTION 'HR_RU_CONVERT_HEX_TO_STRING'
  EXPORTING
    xstring       = x
 IMPORTING
   CSTRING       = y.

WRITE: /, x, / ,y.

I pass the following string to the function: 'A V R A H A M'

and I print in the screen the following one: 'AxVxRxAxHxAxM'. 78 is 'x' hexadecimal code.

Hope it helps.

Avraham

Edited by: Avraham Kahana on Jan 21, 2009 4:44 PM

Read only

Former Member
0 Likes
1,199

Hi,

Convert the XSTRING ti String and replace the space woth '~' and then convert to xstring.

Check these FM

HR_KR_STRING_TO_XSTRING

HR_KR_XSTRING_TO_STRING

Read only

tushar_shukla
Active Participant
0 Likes
1,199

Have you tried below construct ?

REPLACE ......IN BYTE MODE ...

Thanks,

Tushar