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: 

FM to Remove Characters

Former Member
0 Kudos

Hi Fellas ...

I need a FM to remove all kind of characters in a char variable. See the example.


DATA: lv_char TYPE char10 VALUE 'ABC123',
            lv_num  TYPE char 10.

  lv_num = lv_char+3(3).

That is one possibility, however, I also can have:


DATA: lv_char TYPE char10 VALUE 'A1B2C3',
            lv_num  TYPE char 10.

How I can separate the lv_char to have the same 123 in variable lv_num ?

I can have all kind of possibilities of numbers and characters scrambled.

Thx.

7 REPLIES 7

Former Member
0 Kudos

Hi,

You wont need a special FM for this. Have a look at this which was discussed earlier today

Vikranth

Former Member
0 Kudos

Hi,

You could try this small piece of code. I pasted this as a reply for some thread in the morning



DATA : const TYPE string VALUE 'CAD0586/08',
      moff TYPE i,
      mlen TYPE i,
      ans TYPE string,
      len TYPE i,
      temp TYPE i.
FIND REGEX '([[:alpha:]]*)' IN CONST
     IGNORING CASE
     MATCH OFFSET MOFF MATCH LENGTH MLEN.
 
len = strlen( const ).
temp = len - mlen.
ans = const+mlen(temp).
WRITE: ans.

Or if you want only an FM,

go through this link

[]

kesavadas_thekkillath
Active Contributor
0 Kudos

Deleted

Former Member
0 Kudos

Hi,

use SCP_REPLACE_STRANGE_CHARS or

use FM SF_SPECIALCHAR_DELETE

Import parameters Value

WITH_SPECIALCHAR ASDASD@@#$ASDASD<

Export parameters Value

WITHOUT_SPECIALCHAR ASDASDASDASD

or you can use the below statement.

REPLACE ALL OCCURRENCES OF REGEX '[^[:alnum:]]' IN lv_text WITH ''.

or here is another sample code.

first cout the string lenght..

DATA: w_string(255) TYPE c,
      w_str(255) type c,
      w_c1 TYPE i,
      w_c2 TYPE i,
      w_count TYPE i,
      w_sub_str TYPE c.
 
CONSTANTS : c_str(22) VALUE '&*=!@#$%[]{}\^|;`"_~'.   "Prohibited Character still you ca add SPL characters
 
      w_count = STRLEN( w_str ).
*   Clears the string
      CLEAR w_string.
      w_c2 = 0.
      DO w_count TIMES.
        w_sub_str = w_str+w_c1(1).
        IF w_sub_str CN c_str OR w_sub_str EQ space.
            w_string+w_c2(1) = w_sub_str.
            w_c2 = w_c2 + 1.
        ENDIF.
        w_c1 = w_c1 + 1.
      ENDDO.
      CLEAR: w_c1,  w_count.
      SHIFT w_string LEFT DELETING LEADING space.

Edited by: Harini Gopinath on Oct 27, 2009 6:31 PM

Former Member
0 Kudos

try this:

PARAMETERS: text type string.

REPLACE ALL OCCURRENCES OF REGEX '([[:alpha:]])' IN text WITH space.

write text.

venkat_o
Active Contributor
0 Kudos

Hi Bruno, <li>Try this way. I have just come to know this method today.


DATA : lv_char TYPE string VALUE 'A1B2C3'.
REPLACE ALL OCCURRENCES OF REGEX '([[:alpha:]])' IN lv_char WITH space.
write lv_char.
Thanks Venkat.O

Former Member
0 Kudos

Thx all.