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

FM to Remove Characters

Former Member
0 Likes
3,716

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.

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
Read only

Former Member
0 Likes
2,153

Hi,

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

Vikranth

Read only

Former Member
0 Likes
2,153

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

[]

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,153

Deleted

Read only

Former Member
0 Likes
2,153

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

Read only

Former Member
0 Likes
2,153

try this:

PARAMETERS: text type string.

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

write text.

Read only

venkat_o
Active Contributor
0 Likes
2,153

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

Read only

Former Member
0 Likes
2,153

Thx all.