‎2009 Jul 10 7:52 AM
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
‎2009 Jul 10 7:56 AM
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
‎2009 Jul 10 7:55 AM
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
‎2009 Jul 10 7:56 AM
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