‎2009 Sep 02 9:21 AM
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.
‎2009 Sep 02 9:40 AM
hi som,
first confirm if the chars comes only before the numbers or it might be mixed in come cases?
‎2009 Sep 02 9:26 AM
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
‎2009 Sep 02 9:36 AM
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.
‎2013 Dec 05 5:25 AM
‎2009 Sep 02 9:40 AM
hi som,
first confirm if the chars comes only before the numbers or it might be mixed in come cases?
‎2009 Sep 02 9:42 AM
THE CHARS MAY NOT NECESSARILY COME FIRST ALWAYS.. THE NUMS ALSO MAY CUM
‎2009 Sep 02 9:46 AM
Can you send us the sample code that you have written so far.. we wil suggest changes to that.
Ansari
‎2009 Sep 02 9:48 AM
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
‎2009 Sep 02 9:52 AM
sry... my caps lock was on as i was doing some othr wrk.
i dint shout and all..
‎2009 Sep 02 10:07 AM
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
1234hope this is your output
‎2009 Sep 02 12:40 PM
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
‎2009 Sep 02 9:40 AM
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