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

split alphanumeric string

Former Member
0 Likes
3,289

Hi all,

I am a beginner in abap.

I have a requirement.

I need to split an alphanumeric string into numbers and characters.

for eg: ght5678 is my input.

my output should be

ght

5678.

plz hlp me resolv this.

thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,978

hi som,

first confirm if the chars comes only before the numbers or it might be mixed in come cases?

11 REPLIES 11
Read only

Former Member
0 Likes
1,978

Hi..

As you say u r a begineer first lesson is

SEARCH IN SCN BEFORE POSTING..

what u can do is

consider the string is in the variable p_string

find the string lenght using STRLEN. get the value to a var for eg lv_var

do lv_var times.

now u can make use of the system variable SY-ABCDE

enddo.

i am not giving the full logic.. find it o;ut ursel,f

Regards

Ansari

Read only

Former Member
0 Likes
1,978

Hi,

Try this



DATA: var TYPE char25 VALUE 'ght5678',
      moff TYPE i,
      mlen TYPE i,
      alp TYPE char10,
      num type char10,
      len TYPE i,
      off TYPE i.
FIND REGEX '([[:alpha:]]*)' IN var
     IGNORING CASE
     MATCH OFFSET MOFF MATCH LENGTH MLEN.
*WRITE: moff.
*WRITE: mlen.
len = strlen( var ).
*WRITE: len.
alp = var+0(mlen).
num = var+mlen(len).
WRITE:/ alp, num.

Read only

0 Likes
1,978

It was very helpful

Read only

Former Member
0 Likes
1,979

hi som,

first confirm if the chars comes only before the numbers or it might be mixed in come cases?

Read only

0 Likes
1,978

THE CHARS MAY NOT NECESSARILY COME FIRST ALWAYS.. THE NUMS ALSO MAY CUM

Read only

0 Likes
1,978

Can you send us the sample code that you have written so far.. we wil suggest changes to that.

Ansari

Read only

0 Likes
1,978

Well, since he started shouting and can't precisely describe what he wants to do, I'd personally rather back off from helping any further.

Thomas

Read only

0 Likes
1,978

sry... my caps lock was on as i was doing some othr wrk.

i dint shout and all..

Read only

0 Likes
1,978
data : s1 type string value 'char1234'.
DATA: result_tab TYPE match_result_tab,
      res type match_result.
DATA: s2 type string,s3 type string,s4 type string.
DATA: ii type i,c1 type c.
ii = strlen( s1 ).
s4 = s1.
WHILE ii NE 0.
  c1 = s1+0(1).
  TRANSLATE c1 TO UPPER CASE.
if c1 ca sy-abcde.
  CONCATENATE s2 s1+0(1) into s2.
else.
  CONCATENATE s3 s1+0(1) into s3.
endif.
SHIFT s1 left.
ii = ii - 1.
ENDWHILE.

WRITE /: s4,s2,s3.

Output:

char1234
char
1234

hope this is your output

Read only

matt
Active Contributor
0 Likes
1,978

Moderator message to Somdutta

Don't use spelling that you'd use in an SMS message or in Instant Message. Spell words out in FULL. And if you type your message IN ALL CAPITALS, even if it is an accident, then you are shouting.

matt

Read only

Former Member
0 Likes
1,978

Hi,

write like this...Just offset the value..

data:

data(10) type c value 'ght5678',

data1(4) TYPE c,

data2(4) TYPE c.

data1 = data+0(3).

data2 = data+3(4).

write:/ data1,

/ data2.

Regards

Kiran