Application Development 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: 

remove character from a string

Former Member
0 Kudos

wats the command to remove characters in a string?

I have to remove 'bb' from a string

1 ACCEPTED SOLUTION

JozsefSzikszai
Active Contributor
0 Kudos

hi,

you can try the REPLACE statement. There will be a space in the string instead of 'bb', which you can delete with CONDENSE ... NO-GAPS.

hope this helps

ec

7 REPLIES 7

JozsefSzikszai
Active Contributor
0 Kudos

hi,

you can try the REPLACE statement. There will be a space in the string instead of 'bb', which you can delete with CONDENSE ... NO-GAPS.

hope this helps

ec

0 Kudos

If you are replacing bb by ' ' there will be a gap, but why dont you replace it by ''?

0 Kudos

just checked:

DATA : text(10) TYPE c VALUE 'AABBCC'.

REPLACE 'BB' IN text WITH ''.

and really text is 'AACC' after the above

(I remembered so that a space was left there, even if the replacing value was 'nothing' and I had to use the CONDENSE ... NO-GAPS afterwards to delete that unnecessary space. There are two options: 1. My memories are wrong 2. It happened in earlier releases (now I tried in 4.7). Anyway, thanks for your correction!)

0 Kudos

Just said so because the condense may delete gaps which should not be affected...

Nevertheless i cant tell you if this was working different in 4.7. i started to use this command in ERP 2005.

Former Member
0 Kudos

Hello


DATA FIELD(10).
MOVE 'ABCBB' TO FIELD.
REPLACE 'BB' WITH ' ' INTO field.
CONDENSE field.

Former Member
0 Kudos

Hi


DATA lv_field(5).
MOVE 'CCCBB' TO lv_field.
SEARCH lv_field FOR 'BB'.
IF sy-subrc = 0.
  REPLACE 'BB' WITH ' ' INTO lv_field.
  CONDENSE lv_field.
  WRITE lv_field.
ENDIF.

Former Member
0 Kudos

Please do not double-post or cross-post your questions.

We typically delete all the questions when this is found.

Cheers,

Julius