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

Urgent: please reply

Former Member
0 Likes
948

Hi All,

I need to remove all alphabet and only leave numbers for the value of a field.

for example: FIELD1: DVE6837

The output required for FIELD1 is just 6837.

The alphabet is always at the beginning and tehre is no other pattern it follows like fixed length or sequence etc.

Please suggest how to achieve this in the best feasible way. Please reply immediately.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
924

Hi

Try this:

PARAMETERS: P_FIELD(10).

DATA: LEN TYPE I,
      POS TYPE I.

LEN = STRLEN( P_FIELD ).

DO LEN TIMES.

  IF P_FIELD+POS(1) CO SY-ABCDE.
    P_FIELD+POS(1) = SPACE.
  ENDIF.

  POS = SY-INDEX.

ENDDO.

CONDENSE P_FIELD NO-GAPS.

WRITE P_FIELD.

Max

Hi All,

I need to remove all alphabet and only leave numbers for the value of a field.

for example: FIELD1: DVE6837

The output required for FIELD1 is just 6837.

The alphabet is always at the beginning and tehre is no other pattern it follows like fixed length or sequence etc.

Please suggest how to achieve this in the best feasible way. Please reply immediately.

Thanks.

5 REPLIES 5
Read only

Former Member
0 Likes
925

Hi

Try this:

PARAMETERS: P_FIELD(10).

DATA: LEN TYPE I,
      POS TYPE I.

LEN = STRLEN( P_FIELD ).

DO LEN TIMES.

  IF P_FIELD+POS(1) CO SY-ABCDE.
    P_FIELD+POS(1) = SPACE.
  ENDIF.

  POS = SY-INDEX.

ENDDO.

CONDENSE P_FIELD NO-GAPS.

WRITE P_FIELD.

Max

Read only

VXLozano
Active Contributor
0 Likes
924

Ooops! I've reached the post after it was solved... sorry for the spam

And worse than this (for me, of course)... the solution provided before mine is pretty better...

-

-


I would try using the SEARCH sentence. With it, you can look your string for '0', '1', '2'...'9'. If your value is as you've said (once you find a number, the rest of the string will be numbers), take the lower position returned and "cut" your variable from there.

DATA: mystring(10) TYPE c VALUE 'TEST230188',
      mycount TYPE sy-index,
      mynum(1) TYPE n,
      mypos TYPE sy-fdpos.
DO 10 TIMES.
  mycount = sy-index - 1.
  mynum = mycount.
  SEARCH mystring FOR mynum.
  IF sy-fdpos < mypos AND sy-subrc = 0.
    mypos = sy-fdpos.
  ENDIF.
ENDDO.
SHIFT mystring BY mypos PLACES.

(the code is not tested, it's just a sample of what you can do, and I'm sure it can be improved a lot... good luck with it)

Message was edited by: VLozano

Vicenç Lozano

Read only

Former Member
0 Likes
924

Thank you Max!!

Read only

Former Member
0 Likes
924

Hi,

I think you have to check it like this,

data: a type i.

data: c(10) type c value 'asd123'.

data: c1 type i.

data: c2(10) type c.

c1 = strlen( c ).

do c1 times.

if c+a(1) = '1' .

exit.

endif.

a = a + 1.

enddo.

c2 = c+a(c1).

Reward if useful!

Read only

Former Member
0 Likes
924

if u r sure that the alphabet <b>only occurs at the beginning</b> then u can check this sample program

REPORT ZYH284_TEST2.

DATA:

w_char(10) value 'abcd1234',

w_num(10) type n.

w_num = w_char.

write:w_num.