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 from right

Former Member
0 Likes
1,759

hi experts

i want to split a variable with a separator as - (hyphen),

the hyphen can be a anywhere in the string so i want to

split in a such a way that i want to take the word from the very right hand

side . pls help me out to how can i do

for eg.

suppose if the string is like

company-code-date-centre

company-centre

company-code-centre.

from right need to split and take the word centre

i have used the code as

data: text2(50) type c,
text3(53) type c, var1(55) type c.

var1 = wa_final-text1.
split var1  at '-' into text2 text3.
move text3 to wa_final-text3.

but this works only whereever it encounter the first hyphen ....

thanks in advance

Rachel

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
941

Hi,

Use table as destination when splitting:


data: itab type table of string.
data: i_lines type i.
data: result_str type string.

split var1  at '-' into table itab.

"and get number of entries
describe table itab lines i_lines.

read table itab into result_str index i_lines. "and read last entry 
write result_str.

Regards

Marcin

2 REPLIES 2
Read only

Former Member
0 Likes
941

HI,

It is very simple.

Just read the documentation on SPLIT.

You can SPLIT at '-' into an internal table.

So now your last word will be the last record of the internal table.

Just determine the no of records in the internal table making use of DESCRIBE statement and then READ the last record.

data: text2(50) type c,
text3(53) type c, 
var1(55) type c.

types: begin of T_itab,
           text type char50,
         end of T_itab.

data: itab type standard table of t_itab.

data: wa  Type t_itab. 

data: cntr type sytabix.


var1 = wa_final-text1.

split var1 at '-' into itab.

describe table itab lines cntr.

read table itab into wa index cntr.

text3 =  wa-text.

Regards,

Ankur Parab

Edited by: Ankur Parab on Jul 10, 2009 12:26 PM

Read only

MarcinPciak
Active Contributor
0 Likes
942

Hi,

Use table as destination when splitting:


data: itab type table of string.
data: i_lines type i.
data: result_str type string.

split var1  at '-' into table itab.

"and get number of entries
describe table itab lines i_lines.

read table itab into result_str index i_lines. "and read last entry 
write result_str.

Regards

Marcin