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 Statement on Unicode system

Former Member
0 Likes
976

Hi

I am on Unicode system . I am reading a file from application server. i am doing like this

Data:char TYPE C,

test(2000).

READ DATASET DATASET INTO test.

IF SY-SUBRC <> 0. EXIT. ENDIF.

in test i am getting data like 'KK#hh#jkjkjkjk#jkjlk hjkjh hkjh 4354#

<b>I try these both statment.

REPLACE all occurences of CHAR in test WITH space.

REPLACE CHAR WITH ' ' INTO test.</b>

But it’s just replacing the '#' in last occurrence "KK#hh#jkjkjkjk#jkjlk hjkjh hkjh 4354<b>#</b>"

Why its not replacing all with space?

Cheers

Usman

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
914

Are you trying to replace th # with space. If so, the # is not probably not a # but a tab. THe # is an internal representation of tab. You can do this.



REPLACE all occurences of 
       <b>cl_abap_char_utilities=>horizontal_tab</b> in test WITH space.

REgards,

Rich Heilman

7 REPLIES 7
Read only

abdul_hakim
Active Contributor
0 Likes
914

hi

try the below example.

<b>data rule(2) type c value '# '.

translate test using rule.</b>

Cheers,

Abdul Hakim

Read only

Former Member
0 Likes
914

Hi Usman,

Use <b>SPLIT</b> Statement instead of replace this defintely works as it worked for me...

i.e, Split at '#'.

Reward if it helps.

Regards,

Santosh

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
915

Are you trying to replace th # with space. If so, the # is not probably not a # but a tab. THe # is an internal representation of tab. You can do this.



REPLACE all occurences of 
       <b>cl_abap_char_utilities=>horizontal_tab</b> in test WITH space.

REgards,

Rich Heilman

Read only

0 Likes
914

Thanks a lot Rich .

Its removing '#' but not giving spaces ? Why

Its also leaving '#' sign at the end of string

e,g

'KK#hh#jkjkjkjk#jkjlk hjkjh hkjh 4354#

<u><b>after code </b></u>

'KKhhjkjkjkjkjkjlk hjkjh hkjh 4354<b>#</b>

Cheers

Usman

Message was edited by: Usman Akram

Read only

0 Likes
914

Not sure why it is not leaving space. That is strange. The last # must not be a tab, but a CR_LF.

After the REPLACE statement, do it again, this time with.

 cl_abap_char_utilities=>cr_lf

Hopefully it will get rid of the # at the end. If not, then do another REPLACE with the '#' sign.

Regards,

Rich Heilman

Read only

0 Likes
914

Wow, that is weird. I'm seeing the same with it not leaving the space. Anyway. Here is a work around.



report zrich_0006.

data: d1 type localfile value '/usr/sap/nsp/test.txt'.
data: str type string.

open dataset d1 for input in text mode encoding default.

do.

  read dataset d1 into str.
  if sy-subrc <> 0 .
    exit.
  endif.
<b>  replace all occurrences of
              cl_abap_char_utilities=>horizontal_tab
                          in str with '%'.</b>
<b>  translate str using '% '.</b>

  write:/ str.

enddo.

close dataset d1.


REgards,

Rich Heilman

Read only

0 Likes
914

Yes, I dont why its not creating spaces but this work

replace all occurrences of

cl_abap_char_utilities=>horizontal_tab

in str with '%'.

translate str using '% '.

Cheers

Usman