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

Remove non-alpha numerics

Former Member
0 Likes
4,619

I have to remove any non-alpha numerics from something like:

SPMA-09-AF-M002-A7

The result would be:

SPMA09AFM002A7

Is there a function module that would do this?

Edited by: Rob Burbank on Aug 13, 2009 3:44 PM

1 ACCEPTED SOLUTION
Read only

Former Member
2,538

Hi,

Try SCP_REPLACE_STRANGE_CHARS or

use


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

Regards,

Vik

5 REPLIES 5
Read only

Former Member
2,539

Hi,

Try SCP_REPLACE_STRANGE_CHARS or

use


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

Regards,

Vik

Read only

guilherme_frisoni
Contributor
0 Likes
2,538

Hi,

if you know every possible non-alpha chars, you could use translate:

TRANSLATE gc_alpha USING '- '.

CONDENSE gc_alpha NO-GAPS.

Regards,

Frisoni

Read only

Former Member
0 Likes
2,538

Hi,

If it is only one special character You can try like below:


data: lv_hash value '-'.
 replace all occurences of lv_hash by space into variable.

Regards,

Himanshu

Read only

Former Member
0 Likes
2,538

Hi,

Use Replace or Split stmt to do it.

data : a(25) type c VALUE 'SPMA-09-AF-M002-A7',
       a1 type c value '-'.

replace  ALL OCCURRENCES OF a1 in a WITH space.

write: a.

data : begin of itab OCCURS 0,
        text(50) type c,
      end of itab.

data : a(25) type c VALUE 'SPMA-09-AF-M002-A7',
       a1 type c value '-'.

data b(50) type c.

      SPLIT a at a1 INTO TABLE itab.

      loop at itab.
        CONCATENATE itab-text
                    b
                INTO b.
       endloop.

       write b.

Thanks & regards,

ShreeMohan

Read only

Former Member
0 Likes
2,538

I don't think there is any function module for that but you can write simple code as follows.

PARAMETERS: p_string(20) TYPE c.

DATA: v_length TYPE i,
      v_offset TYPE i.

START-OF-SELECTION.
  WRITE:/ p_string.
  v_length = STRLEN( p_string ).
  CHECK v_length > 0.
  DO v_length TIMES.
    v_offset = sy-index - 1.
    IF p_string+v_offset(1) CA '0123456789' OR
       p_string+v_offset(1) CA sy-abcde.
    ELSE.
      CLEAR p_string+v_offset(1).
    ENDIF.
  ENDDO.
  CONDENSE p_string NO-GAPS.
  WRITE:/ p_string.