ā2012 Jun 28 11:33 AM
I have a requirement.....I have strinf for ex. INT,CHAR,BHB,BNVB,
I have to replace the last occurance of , into .
It will look like INT,CHAR,BHB,BNVB.
Please help.
ā2012 Jun 28 12:41 PM
ā2012 Jun 28 11:38 AM
Hi Sanghamitra,
You can do 2 things.
1. Reverse the string and use REPLACE FIRST OCCURRENCE statement.
2. Or else, search for the offset of last , and then replace that offset using REPLACE SECTION statement.
Hope it helps you.
Regards,
Sindhu Pulluru.
ā2012 Jun 28 12:10 PM
Hi,
You can try the following:
data: v_str type string,
l_lines type i.
v_str = ' INT,CHAR,BHB,BNVB,'.
Split v_str at ',' into table itab.
describe table itab lines l_lines.
read table itab into w_tab index l_lines.
if sy-subrc eq 0.
replace ',' with '.' in w_tab.
modify itab from w_tab index l_lines.
endif.
ā2012 Jun 28 12:41 PM
ā2016 Jan 08 3:23 PM
Very nice hint! But I had to use '.$' instead of ',$' to make it work.
ā2012 Jun 28 1:27 PM
Hi,
You can try the following
data: lv_data TYPE string value 'int,ban,sit,viu,',
lv_len TYPE i,
lv_data1 TYPE char25.
lv_data1 = lv_data.
lv_len = strlen( lv_data ).
lv_len = lv_len - 1.
lv_data1+lv_len(1) = '.'.
write: / lv_data.
skip.
write: / lv_data1.
ā2016 Jan 08 4:03 PM
Hello Sanghamitra,
When you say 'last occurrence...' does that mean the last character? If so, Uwe's statement (and Mayur's code) would work.
But if the below string qualifies for your idea of 'last occurrence' then the solutions given by Uwe and Mayur won't work.
INT,CHAR,BHB,BNVB
Can you clarify?
-Amit.
ā2016 Jan 08 4:12 PM
ā2016 Jan 08 4:21 PM