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

Need a split logic.

Former Member
0 Likes
1,130

I am having a string, for example : (1) 6V_EGD, i need 6 out of this

(2) 107V_EGDH, i need 107 out of this.

Plz send me the logic for this.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,098

Hi,

Please refer the code below :



data : string(20) type c value'12ABAP',
       num(20) type n.

num = string.

SHIFT num left DELETING leading '0'.

write : num.

Thanks,

Sriram POnna.

10 REPLIES 10
Read only

Former Member
0 Likes
1,098

string+0(1) will give u 6

string+0(3) will give u 107

pk

please ignore this answer provided by me.

i thought u wanted to print values "6' and '107'.

pk

Edited by: prashanth kishan on Jun 25, 2008 7:21 AM

Read only

Former Member
0 Likes
1,098

Hi Dilip,

Try the following:

1. string1 = 6V_EGD:

string1(1) gives 6

2. string2 = 107V_EGDH

string2(3) gives 107.

Hope This Helps You.

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
1,099

Hi,

Please refer the code below :



data : string(20) type c value'12ABAP',
       num(20) type n.

num = string.

SHIFT num left DELETING leading '0'.

write : num.

Thanks,

Sriram POnna.

Read only

former_member156446
Active Contributor
0 Likes
1,098

Hi there I just made it.. check this might work


(1)vl_type1 = 6V_EGD, i need 6 out of this
(2)vl_type2 = 107V_EGDH, i need 107 out of this.

vl_1 type i, vl_2 type i. catch the string length in these fields..

do vl_1 times.

vl_buff = vl_type1+ sy-index(1).

if not vl_buff CA sy-abcde.
concatenate vl_buff  vl_ouput to vl_output.
endif.

else.
skip / exit.  " debug and check which is suitable.
endif.

clear: vl_buff,
enddo.
condense vl_output no gaps.

Read only

vinod_vemuru2
Active Contributor
0 Likes
1,098

Hi Dilip,

After the number if u always have letter V i.e V_ some thing then do like this.


DATA: l_string TYPE string,
 l_string1 TYPE string,
l_string2 TYPE string.

l_string =  '6V_EGD'.
SPLIT l_string AT 'V' INTO l_string1, l_string2.

WRITE l_string1.  "Here u have 6 now.

Thanks,

Vinod.

Read only

Former Member
0 Likes
1,098

hi,

if text1 = (1) 6V_EGD: 6 is in the 5th place..so it is text1+4(1)

(2) 107V_EGDH: text2+4(3).

regards,

madhu

Read only

Former Member
0 Likes
1,098

hi,

try this one......

data : st_1 type string value '6sahg'.

data : ch_1 type c.

ch_1 = st_1.

write : ch_1.

o/p : 6

-


data : st_1 type string value '623sahg'.

data : ch_1(3) type c.

ch_1 = st_1.

write : ch_1.

o/p : 623

Mark the post answered once ur problem is solved ....

Read only

Former Member
0 Likes
1,098

Hi,

data:

str1(10),

str2(10).

str1 = '6V_EGD'.

str2 = '107V_EGDH'.

str1(1) . "To get 6

str2(3). " To get 107

Read only

Former Member
0 Likes
1,098

Thanx Sriram Ponna

Read only

Former Member
0 Likes
1,098

hi

you can do it in two ways.

if u want to split from the begining use

string1(1) gives u 6.

string2(3) gives u 107.

but if u want split not from first position then use offsets.

string1+0(1) gives u 6.

string2+0(3) gives u 107.

hope this will help.

reward points if useful.

regards

Sumit Agarwal