Skip to Content
author's profile photo Former Member
Former Member

String manipulation - REPLACE ALL OCCURRENCES

Hi All,

We are using R/3 4.6C and for some reason, the command REPLACE ALL OCCURRENCES OF... is not recognised by the compiler. Is it because the this was introduced from the later versions?

If so can you please suggest an alternative to remove any special characters from a string.

Thanks!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 27, 2008 at 05:11 PM

    Hi Sandeep,

    Try this

    in the below string # is replaced by space

    REPORT  YCHATEST                                .
    
    DATA : V_STRING TYPE STRING.
    
    V_STRING = 'avvvvvv#kjkjkjdfk#jkjklsf#'.
    
    TRANSLATE V_STRING USING '#  '.
    
    CONDENSE V_STRING no-gaps.
    
    WRITE : V_STRING. 

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 27, 2008 at 05:26 PM

    Hi All,

    Thank yoy for your replies.

    All occurences is still not working.

    I am trying out the other solutions as well.

    Can you also please let me know how I can replace ' (single quote)?

    How do I specify this?

    Thanks!

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 27, 2008 at 05:29 PM

    Maybe not the most efficient, but it seems to do what you want.

    REPORT zz_temp.
    
    DATA: g_v_string(80)          TYPE c VALUE '123!@#abcDEF$%^456$%^xyz',
          g_v_printable_chars(62) TYPE c,
          g_v_alpha(52)           TYPE c VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuzwxyz',
          g_v_integers(10)        TYPE c VALUE '0123456789',
          g_v_len                 TYPE i.
    
    CONCATENATE  g_v_alpha g_v_integers INTO g_v_printable_chars.
    
    g_v_len = STRLEN( g_v_string ).
    
    WHILE sy-index LT g_v_len.
      IF g_v_string+sy-index(1) CN g_v_printable_chars.
        g_v_string+sy-index(1) = space.
      ENDIF.
    ENDWHILE.
    
    CONDENSE g_v_string NO-GAPS.
    
    WRITE :/ g_v_string.

    Edited by: Jerry Coleman on Mar 27, 2008 1:44 PM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 27, 2008 at 05:46 PM

    Hi sandeep,

    the solution which i can see is.. .. as follows..:

    1) find out the length of string ex: v_length = strlen(v_str).

    2) use do loop.....

    do v_length times.
                                   v_index = sy-indiex.
                                   
                                   if v_str+v_index(1) CA (a-z or 0-9).
                                    l_str+ctr(1) = v_str+v_index(1).  
                                    ctr = ctr + 1.
                                   endif.
                               endloop.

    3) in the above code i am trying to read the characters which is not special characters....

    all the very best.....

    regards,

    sreenivasa sarma k.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 27, 2008 at 05:09 PM

    hi , i think this is working...check it..

    data:char(25) value '5#4#2#&1#&',

    char1(9) .

    replace all occurrences of '#' in char with 'and' .

    replace all occurrences of '&' in char with 'num' .

    write: char.

    regards,

    venkat.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 27, 2008 at 05:11 PM

    You can use this...

    DATA: text TYPE string.
    
    text = 'Blag$is$an$ABAP$Consultant'.
    
    WHILE sy-subrc EQ 0.
      REPLACE '$' WITH space
      INTO text.
    ENDWHILE.
    
    WRITE:/ text.
    

    Greetings,

    Blag.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Mar 27, 2008 at 05:13 PM

    Try and use the 'old' REPLACE statement. Look for exact syntax at help.

    You might be right that this statement is not yet valid for you release, but the 'old' REPLACE will also do the trick, but in that case you will have to do it in a DO-ENDDO loop since you can't replace them all at once like the ALL OCCURENCES variant.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 27, 2008 at 05:57 PM

    Thank you all for ur replies. I am awarding points to most of you.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.