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

String operation?

Former Member
0 Likes
976

Hi Everybody,

From a string of variable length how can I seperate alphabets and integers? Eagerly waiting for ur reply?

Regards,

Pulokesh

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
949

data : text(40) type c value '152as1an',
       num(20),
       chr(20),
       pos type i,
       len type i,
       v_ch.

compute len = strlen( text ).

do len times.
v_ch = text+pos(1).
if v_ch ca '0123456789'.
concatenate num v_ch into num.
condense num no-gaps.

else .
concatenate chr v_ch into chr.
condense chr no-gaps.
endif.
pos = pos + 1.

enddo.


write : / num,20 chr.

regards

shiba dutta

8 REPLIES 8
Read only

Former Member
0 Likes
949

hi,

refer

Hope this solves your purpose.

Award points if it helps.

-Gaurang

Read only

Former Member
0 Likes
949

hi Pulokesh,

Check out this way


data: v_char_field(100),
v_qty_num type rl03t-pickm.

call function 'MOVE_CHAR_TO_NUM'
exporting
chr = v_char_field
importing
num = v_qty_num
exceptions
convt_no_number = 1
convt_overflow = 2.

if sy-subrc <> 0.
"write/throw error message
endif.


2)QSS0_CHAR_FLTP_CONVERSION.

Read only

Former Member
0 Likes
949

Hi,

<b>do strlen times</b> .

<b>if w_str ca sy-abcde .</b>

w_alpha = w_strw+0(1) .

<b>else</b>.

w_num = w_strw+0(1) .

<b>endif.</b>

<b>left shift w_str .</b>

<b>enddo</b>.

Regards Praveen.

Read only

Former Member
0 Likes
950

data : text(40) type c value '152as1an',
       num(20),
       chr(20),
       pos type i,
       len type i,
       v_ch.

compute len = strlen( text ).

do len times.
v_ch = text+pos(1).
if v_ch ca '0123456789'.
concatenate num v_ch into num.
condense num no-gaps.

else .
concatenate chr v_ch into chr.
condense chr no-gaps.
endif.
pos = pos + 1.

enddo.


write : / num,20 chr.

regards

shiba dutta

Read only

0 Likes
949

Hi,

Thanks for the help.

Regards,

Pulokesh

Read only

Former Member
0 Likes
949

Hi karmakar,

<b>Reexecute this code....... I have just now to get your problem solved.</b>

*************************************************

parameters:

p_string(30) TYPE c.

data:

w_ints(30) TYPE c,

w_chars(30) TYPE c,

w_index TYPE i.

DO 30 TIMES.

if p_string+w_index(1) CO SY-ABCDE.

concatenate p_string+w_index(1) ' ,' w_chars INTO w_chars.

elseif p_string+w_index(1) CO '0123456789'.

concatenate p_string+w_index(1) ' ,' w_ints INTO w_ints.

endif.

w_index = w_index + 1.

ENDDO.

write: / 'Characters are :',w_chars,

/ 'Integers are :', w_ints.

*************************************************

<b>

Reward all helpful answers</b>

Regards,

V.Raghavender.

Read only

former_member673464
Active Contributor
0 Likes
949

hi..

Just move the field(characters) to variable of type <b>numc</b> to get the integers only.

Then compare string with sy-abcde and the get the alphabets into another variable.

Message was edited by:

veereshbabu ponnada

Read only

Former Member
0 Likes
949

Hi,

check this code.

data:char(10) value '1h3h4g4'.

data:str(10).

data:num(10).

data:len(2) type n.

data:n type n.

len = strlen( char ).

do len times.

if sy-abcde cs char+n(1).

concatenate str char+n(1) into str.

else.

concatenate num char+n(1) into num.

endif.

n = n + 1.

enddo.

write:/ str,/ num.

rgds,

bharat.