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

How to split the numeric and character in string?

Former Member
0 Likes
8,823

Dear all

I have a problem with the split string to detach the numeric and character

For example:

Str1=u2019123.456 abcdu2019

I want the return value is u2018123.456u2019 ,removed the u2018abcdu2019

In this example the character u2018abcdu2019 maybe dynamic bits or value.

It can u2018abcu2019 or can u2018abcdeu2019 or can u2018abdu2019 etc..

How do to do it ?

Thanks

Sun

1 ACCEPTED SOLUTION
Read only

valter_oliveira
Active Contributor
0 Likes
3,637

Are the letters always in the end? And starting in position 8? Or having the space between numbers and letters? This is usefull info that could allow us to give you the BEST solution.

However, I'll give you a generic solution that will allways work (I hope ).


DATA: lenght TYPE i,
      pos(2) TYPE n,
      str1   TYPE char255 VALUE '123.456 abcd'.
lenght = strlen( str1 ).
CLEAR pos.
DO lenght TIMES.
  IF NOT str1+pos(1) CO '0123456789.'.
    CLEAR str1+pos(1).
  ENDIF.
  ADD 1 TO pos.
ENDDO.
CONDENSE str1.

Regards.

Valter Oliveira.

9 REPLIES 9
Read only

Former Member
0 Likes
3,637

Hi Sun,

str2 = str1(7).

Regards, Dieter

Read only

0 Likes
3,637

will not work with "122.34 abcd"

Read only

0 Likes
3,637

Hi Rainer,

sure, but has the value allways a lenght of 7 or does it has an dynamic lenght??

Do you know the answer?

regards, Dieter

Read only

Former Member
0 Likes
3,637

data : var(10) type n,

var1(10) type c value '12.34VBFG'.

move var1 to var.

write var.

Read only

Former Member
0 Likes
3,637

This message was moderated.

Read only

valter_oliveira
Active Contributor
0 Likes
3,638

Are the letters always in the end? And starting in position 8? Or having the space between numbers and letters? This is usefull info that could allow us to give you the BEST solution.

However, I'll give you a generic solution that will allways work (I hope ).


DATA: lenght TYPE i,
      pos(2) TYPE n,
      str1   TYPE char255 VALUE '123.456 abcd'.
lenght = strlen( str1 ).
CLEAR pos.
DO lenght TIMES.
  IF NOT str1+pos(1) CO '0123456789.'.
    CLEAR str1+pos(1).
  ENDIF.
  ADD 1 TO pos.
ENDDO.
CONDENSE str1.

Regards.

Valter Oliveira.

Read only

0 Likes
3,637

Congrats Valter. Good Solution. I appreciate your answer.

Read only

0 Likes
3,637

Thanks for all.

the problem has solved.

Sun

Read only

Former Member
0 Likes
3,637

Hi,

Try following code:

IF <field> CA sy-abcde.

length = sy-fdpos - 1.

string = <field>+0(leneth).

ENDIF.

Regards,

Kunjal