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 Alphanumeric charaters from a field

Former Member
0 Likes
1,209

I have a field which can have value as ABCD0123ef. Is there a function module which would return just the numeric part of it i.e 0123.

Please advise.

I have a field which can have value as ABCD0123ef. Is there a function module which would return just the numeric part of it i.e 0123.

Please advise.

10 REPLIES 10
Read only

Former Member
0 Likes
1,181

Hi,

try this

data:v_type type char15 value 'ABCD0123e1f'.

data:v_num(10) type n.

v_num = v_type.

write:/ v_type,

v_num.

assign variable to a Numc type field.

Thanks,

Vamshi.

Read only

0 Likes
1,181

Vamshi,

This returns 0000001231 and not 01231. Any clues

Read only

0 Likes
1,181

It's because the lenght of the string....You can use...


DATA: TEST(5) TYPE N.

That way, your going to have <b>01231</b> instead of <b>0000001231</b>

Greetings,

Blag.

Read only

0 Likes
1,181

That is not possible to define it before hand as numc(5). it could also be ABCD012334404ef.

Read only

0 Likes
1,181

Ok...It took me a while...But this code works -;)


DATA:v_type TYPE string VALUE 'ABCD012334404ef'.
DATA: regex TYPE string.

regex = 'D+'.
REPLACE REGEX regex IN v_type WITH space.
regex = 'D+'.
REPLACE REGEX regex IN v_type WITH space.

WRITE:/ v_type

Greetings,

Blag.

Read only

0 Likes
1,181

The code doesn't compile using the REGEX word as it is a reserved word.

Read only

0 Likes
1,181

Really? It compiled in my box...LOL


DATA:v_type TYPE string VALUE 'ABCD012334404ef'.
DATA: reg_ex TYPE string.
 
reg_ex = 'D+'.
REPLACE REGEX reg_ex IN v_type WITH space.
reg_ex = 'D+'.
REPLACE REGEX reg_ex IN v_type WITH space.
 
WRITE:/ v_type

This should works fine -;)

Greetings,

Blag.

Read only

0 Likes
1,181

RegEx or Regular Expressions is only supported in NetWeaver 7.0.

Regards,

RIch Heilman

Read only

0 Likes
1,181

Easy, simple way is something like this.


REPORT  zrich_0002.

data: lv_str type string.
data: lv_str2 type string.
data: subset type string.
data: offset type i.
data: len type i.

lv_str = 'ABCD012334404ef'.
len = strlen( lv_str ).

do len times.
  subset = lv_str+offset(1).
  if subset CA '0123456789'.
    concatenate lv_str2 subset into lv_str2.
  endif.
  offset = offset + 1.
enddo.

write:/ lv_str2.

Regards,

RIch Heilman

Read only

Former Member
0 Likes
1,181

Hi Ankur,

Try this,

DATA : TEXT(100) TYPE C.

TRANSLATE TEXT USING 'A B C......X Y Z'.

Hopes it helps you.

Ali