10-07-2009 6:20 AM
Hello,
I require last text from below eg:
field1 = text1|text2|text3.
field2 = text1|text2|text3|text4.
field3 = text1|text2|text3|text4|text5..
how can i get only text3 from field1.....text4 from field2.
Regards,
Rachel
10-07-2009 6:28 AM
Hi,
Are there any field separators or delimiters used in ur fields .If so,you can split and then extract the desired text from ur field.
split field1 at <delimiter> into text1 text2 text3
Alternatively by knowing string length and using offset value you can be able to get the texts from the fields.
regards,
Lakshman.
10-07-2009 6:28 AM
Hi,
Are there any field separators or delimiters used in ur fields .If so,you can split and then extract the desired text from ur field.
split field1 at <delimiter> into text1 text2 text3
Alternatively by knowing string length and using offset value you can be able to get the texts from the fields.
regards,
Lakshman.
10-07-2009 6:30 AM
Hi
If you know the length of the text, then its easy. Suppose the length of the last text is 10 char. Then following things to be done.
Data: l_n type i.
l_n = strlen (field1) - 10.
last text = field1+l_n(10).
Please check if this works.
Thanks
Sourav
10-07-2009 6:34 AM
Hello
If '|' is delimiter then:
data: begin of itab,
text(20),
end of itab.
data: n type i.
split field1 at '|' into table itab.
describe table itab lines n.
read table itab index n.
write itab-text.
... etc for field2, field 3 .....
10-07-2009 6:36 AM
if there is a seperator the go for this
data:input type string.
data:itab type table of char10.
data:wa like line of itab.
input = 'text1|text2|text3'.
split input at '|' into TABLE itab.
sort itab DESCENDING.
read table itab index 1 INTO wa.
write wa.
10-07-2009 6:57 AM
> I require last text from below eg:
> how can i get only text3 from field1.....text4 from field2.
So, what is your problem? To get the last text or to get the third text?
10-07-2009 7:02 AM
Hello Rachel,
A small variation of Keshu's solution:
DATA:
ITAB TYPE STANDARD TABLE OF STRING,
V_OUTPUT TYPE STRING,
V_LINES TYPE I.
SPLIT V_INPUT AT '|' INTO TABLE ITAB.
V_LINES = LINES( ITAB ).
READ TABLE ITAB INTO V_OUTPUT INDEX V_LINES.
BR,
Suhas
10-07-2009 7:10 AM
Hi,
<li>Try this way.
Thanks
Venkat.O
report ztest.
data:field type string VALUE 'text1|text2|text3|text4|text5'.
DATA:last_field type string.
DATA:it_data type TABLE OF string.
DATA:wa_data LIKE LINE OF it_Data.
SPLIT field at '|' INTO TABLE it_data.
DESCRIBE TABLE it_data LINES sy-tfill.
READ TABLE it_data INTO wa_data INDEX sy-tfill.
last_field = wa_data.
WRITE last_field.
10-07-2009 7:15 AM
Hi,
You have:-
field1 = text1|text2|text3.
field2 = text1|text2|text3|text4.
field3 = text1|text2|text3|text4|text5.
Refer:-
DATA : v_lines TYPE i.
DATA : itab TYPE STANDARD TABLE OF string.
DATA : wa LIKE LINE OF itab.
SPLIT field1 AT '|' INTO TABLE itab.
DESCRIBE TABLE itab
LINES v_lines.
"read last text
READ TABLE itab INTO wa INDEX v_lines.
IF sy-subrc = 0.
"now you have the last text in work area
ENDIF.
Similarly you can use field2 and field3 to get the last text.
Hope this helps you.
Regards,
Tarun
10-07-2009 8:20 AM