2013 Sep 26 4:48 PM
Hi Experts,
I have small query,
Let's say i have data in notepad as
abc,"sunil,kumar",100,"praveen,kumar".
xyz,"sateesh,kumar",200,"sukesh,kumar".
Now my requirement is , i want to replace the , with + symbol but the , in the (double quotes) should remain as it is.
My Expected output is :
abc+"sunil,kumar"+100+"praveen,kumar".
xyz+"sateesh,kumar"+200+"sukesh,kumar".
Hope u got my question.
Regards,
RaviChandra.
2013 Sep 26 8:51 PM
This will do the job.
If each line is separated by commas and ends with a period:
REPLACE ALL OCCURENCES OF REGEX ',(?![^"]*"(,|\.))' IN lt_text WITH '+'.
If the periods are not at the end of the line:
REPLACE ALL OCCURENCES OF REGEX ',(?![^"]*"(,|$))' IN lt_text WITH '+'.
2013 Sep 26 5:01 PM
You can use REPLACE command.
It's very simple. Please, see its sintax on the internet.
Regards.
Vinícius Ostan
2013 Sep 26 5:07 PM
Hi Ravi,
First Take the Note pad content into the characters, then Use the command Replace for those you want to do.
2013 Sep 26 5:10 PM
Hi all
I have used the replace statement but it is converting all the , into + .
I have done this already but not getting.
Please once check the requirement clearly.
2013 Sep 26 5:09 PM
2013 Sep 26 5:25 PM
Hi bagchi,
Thanx for the reply,
But in my requirement i have get the data with some numbers like
abc+"sunil,kumar"+100+"praveen,kumar",250,200,Hyderabad,Andra Pradesh,India
But for the above string it won't work.
2013 Sep 26 6:14 PM
Hi Ravi,
You need an indicator that needs to be unique.
Otherwise, you won't identify which character needs to be changed or not.
Can't you talk with your function about it?
Best regards.
2013 Sep 26 6:18 PM
Hi
Do u have any idea regarding how to extract the data which is present in double quotes ,
Let say in the below string.
abc+"sunil,kumar"+100+"praveen,kumar".
i want to extract sunil,kumar and praveen,kumar .
Is there any possibility to achieve this.
Regards,
RaviChandra.
2013 Sep 26 6:35 PM
Can we try with split Statement, Will it work?
Splitting Character Strings (SAP Library - ABAP Programming (BC-ABA))
For reference use the upper link..
I thing it will work. Split your string from +.
2013 Sep 26 6:49 PM
Try something like below:
data: string(50) type c,
symbol1(1) type c,
symbol2(1) type c,
symbol3(1) type c,
part1(10) type c,
part2(10) type c,
part3(10) type c,
part4(10) type c.
symbol1 = '"'.
symbol2 = ','.
symbol3 = '+'.
string = 'abc,"sunil,kumar",100,"praveen,kumar".'.
SPLIT string AT symbol INTO part1 part2 part3 part4.
concatenate symbol1 part1 symbol1 into part1.
replace all occurrences of symbol2 in part2.
concatenate symbol1 part3 symbol1into part3.
replace all occurrences of symbol2 in part4.
concatenate part1 part2 part3 part4 into string separated by symbol3
2013 Sep 26 6:50 PM
Hi Shekar
I tried with Split statement but it is not getting.
Regards,
RaviChandra
2013 Sep 26 6:53 PM
2013 Sep 26 6:58 PM
Hi Jeevan,
Thanx for the reply,
I think the code will work if the string is of format which is given by me,
If the string format is different then the code need to be changed .
the string may differ with , and " , " .
The above is just a sample record i have given,
I think we can do it by using the wild card search.
Pleaase can any body let me know how to store the '"*,*"' into one variable using search statement .
Pleaase let me know.
Regads,
RaviChandra.
2013 Sep 26 8:30 PM
Hi Ravi,
Please copy/paste the code below, run it on debug mode then see the it_string2 table, there you'll find your value separated correctly in each line.
DATA string(50).
DATA string2(50).
DATA p1 TYPE sy-index.
FIELD-SYMBOLS <fs_string> TYPE any.
DATA it_string TYPE TABLE OF string.
DATA it_string2 TYPE TABLE OF string.
APPEND 'abc,"sunil,kumar",100,"praveen,kumar".' TO it_string.
LOOP AT it_string INTO string.
DO .
p1 = sy-index - 1.
ASSIGN string+p1(1) TO <fs_string>.
IF <fs_string> IS ASSIGNED.
IF <fs_string> EQ '"' .
DO.
IF sy-index EQ 1.
CLEAR <fs_string>.
CONTINUE.
ELSEIF <fs_string> EQ '"'.
APPEND string2 TO it_string2.
CLEAR string2. CLEAR <fs_string>.
CONTINUE.
ENDIF.
CONCATENATE string2 <fs_string> INTO string2.
p1 = p1 + 1.
ASSIGN string+p1(1) TO <fs_string>.
IF <fs_string> IS NOT ASSIGNED.
EXIT.
ENDIF.
ENDDO.
ELSE.
CLEAR <fs_string>.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
BREAK-POINT.
Regards,
I hope it can help you.
Regards.
2013 Sep 26 7:26 PM
Hi Ravi,
I have not tested this code.
But you can use this logic.
string2(50)
string1 = abc,"sunil,kumar",100,"praveen,kumar".
length = strlen( string1 ).
int i.
do.
if i GT length. " Do only till the length of string.
exit.
endif.
if string1+i(1) = ' " ' . "If an open quote comes, copy till the closing quote.
do.
concatenate string2 string1+i(1) into string2.
if string1+i(1) = ' " ' .
exit.
endif.
i = i+1.
enddo.
elseif string1+i(1) = ' , ' . "If its a comma, replace it with a '+'
concatenate string2 '+' into string2.
i = i+1.
else.
concatenate string2 string1+i(1) into string2. " Else just copy that character to the string.
i = i+1
endif.
enddo.
Let me know if it gives the required output.
Regards,
Susmitha
2013 Sep 26 7:58 PM
Hi susmitha,,
Thanx for the reply,
I have tried with ur code, it is not satisfying for some of the records
do u have any other apporach, i think wild card search will satisfy my requirement,
Do u have any idea on how to store the wild card search in one variable,like i want to store '"*"' in one variable and then want to replace the , with space and then concatenate the string in the same location.
Hope u got my quesiton.
Thanx again.
2013 Sep 26 8:05 PM
Can you give an example of the records that the above logic didn't satisfy?
2013 Sep 26 8:11 PM
Hi
Can you explain with the wild card search. I will paste the records once i login to system again.
I have a records which has length of 1200 ( In the flat file i have fields for 200 ) so i think we can have some performance impact ( not sure about it) but i heard that wild card search will satisfy the requirement.
Please express ur view on it
Thanx alot again.
2013 Sep 26 8:32 PM
Check this link.
http://help.sap.com/SAPHELP_470/Helpdata/EN/fc/eb33cc358411d1829f0000e829fbfe/content.htm
Search for *pattern gives a word ending with pattern and <pattern>* gives a word beginning with pattern.
And words are separated by space, comma, periods, semicolon etc.
So search for "* gives the position of the start of string in *, and search for *" gives the position of the end of string.
I hope this was what you wanted.
2013 Sep 26 8:32 PM
Ravi Chandra wrote:
i heard that wild card search will satisfy the requirement.
Where did you hear that? How do you think a wild card would satisfy your requirement?
Imagine if you search *,* in this even ",n or k," or even something like <200 characters>,<300 characters> will satisfy the condition and how are you gonna specify the length your wild card.Also system will not return the part of the string to you, it's just gonna set values to some system variables like sy-subrc.
2013 Sep 26 8:40 PM
Hi jeevan,
Thanx for the reply,
I am just thinking wild card may satisfy my requirement , i m not sure whether it will satisfy or not. Unless i get some input.
Will update if i get any input
Regards,
RaviChandra.
2013 Sep 26 8:51 PM
This will do the job.
If each line is separated by commas and ends with a period:
REPLACE ALL OCCURENCES OF REGEX ',(?![^"]*"(,|\.))' IN lt_text WITH '+'.
If the periods are not at the end of the line:
REPLACE ALL OCCURENCES OF REGEX ',(?![^"]*"(,|$))' IN lt_text WITH '+'.
2013 Sep 27 9:32 AM
Hi Eric,
Thanx alot...
It work pretty Good...
Regards,
RaviChandra.
2013 Sep 26 9:21 PM
Hi,
This may be a little unconventional, but...
Save the file as a comma delimeted text file (i.e. just save the notepad .txt file)
Open the text file in Excel as a comma delimited text file.
Save the file in Excel as a tab delimited text file.
Now you can replace the tabs with "+" and not destroy the commas within the names.
Good Luck.
Regards,
mr. kim
2013 Sep 26 9:26 PM
Ravi,
I've tested the code above and it works fine to me.
Please, let me know if it can help you.
Regards.
Vinicius Ostan