‎2006 Aug 04 7:30 PM
Hi All,
I am trying to get rid of single quotes ie, ', from my text field and replace it with blank, any idea how the code should look like, double quotes have no issues , '"', works but what to write anout single quotes,''' doesnt work.
Sorry , if it sounds very easy, may be I am missing out soemthing.
Thanks in Advance
Tina
‎2006 Aug 04 7:38 PM
Hi Tina, ABAP is a little funny when dealing with single quotes. Check the following program, notice that for one single 'quote, we need to use 2 and then of course wrap with quotes which give you a total of 4.
report zrich_0001.
data: text type string.
text = 'This is a string with a '' in it, lets get rid of it'.
replace '''' with space into text.
write:/ text.
Regards,
Rich Heilman
‎2006 Aug 04 7:38 PM
Hi Tina, ABAP is a little funny when dealing with single quotes. Check the following program, notice that for one single 'quote, we need to use 2 and then of course wrap with quotes which give you a total of 4.
report zrich_0001.
data: text type string.
text = 'This is a string with a '' in it, lets get rid of it'.
replace '''' with space into text.
write:/ text.
Regards,
Rich Heilman
‎2006 Aug 04 7:46 PM
HI,
see the below program
REPORT Y_TEST.
data: text(10).
text = 'sudh''eer'.
write: text.
replace '''' with SPACE into text.
write:/ text.Thanks
Sudheer
‎2006 Aug 04 7:57 PM
Hey , what if my character i 'subh'eer'?
and I want to get rid of ' in the middle.
thanks in advance.
‎2006 Aug 04 8:03 PM
In the ABAP command if you wish to use single quotes a single quote previous to it indicates that you wish to enter a single quote.
REPLACE l_string with ''' '.
means replacing the first occurence of single quote to space. Surely if you wish to replace mulitple occurence better use TRANSLATE.
Regards
Anurag
‎2006 Aug 04 8:09 PM
hi tina,
try using the Translate command with which u can replace all the occurences..
‎2006 Aug 04 7:59 PM
Hi tina,
if u want to pass a string with single quote to a variable say 'text's' to v_data it considers the first occurence of ' after t as the end of the text and it gives u a syntax error.
data: v_data type string value 'text's'.
error: unable to interpret s after '.
hope this helps.
regards,
keerthi.
‎2006 Aug 04 8:42 PM
Hi All ,
thanks for your help.
I meant my work area is holding value like
wa = "ajsja"xaj'asa . These are all values.
if wa-txt ca '"'.
REPLACE all occurrences of '"' in wa-txt WITH space.
endif.
if wa-txt ca `'`.
REPLACE all occurrences of `'` in wa-txt WITH space.
endif.
Shoud this not work.?
‎2006 Aug 04 8:45 PM
I feel the below would give syntax error.
if wa-txt ca `'`.
REPLACE all occurrences of `'` in wa-txt WITH space.
endif.
try using
if wa-txt ca `''`.
REPLACE all occurrences of `''` in wa-txt WITH space.
endif.
Regards
Anurag
‎2006 Aug 04 8:46 PM
‎2006 Aug 04 8:49 PM
Hi,
This statement works, the second one is tild ` and not', also I ran in debug mode, one issue is it does not insert spaces , it remves the character just. I actually wanted aga'aah to aga aah.
‎2006 Aug 04 8:50 PM
‎2006 Aug 04 8:53 PM
‎2006 Aug 04 8:54 PM
Take this program for example, it remove both single quotes and double quotes and leaves the spaces.
report zrich_0002.
data: wa-txt type string.
wa-txt = '"This" aga''aah'.
if wa-txt ca '"'.
translate wa-txt using '" '.
endif.
if wa-txt ca ''''.
translate wa-txt using ''' '.
endif.
write:/ wa-txt.
Regards,
Rich Heilman
‎2006 Aug 04 8:57 PM
Ok, so tild doesn't work in 46c, but it definitly does work in a WebAS 7.0. Just tested, it works.
report zrich_0002.
data: wa-txt type string.
wa-txt = `"This" aga'aah`.
if wa-txt ca `"`.
translate wa-txt using `" `.
endif.
if wa-txt ca `'`.
translate wa-txt using `' `.
endif.
write:/ wa-txt.
Regards,
Rich Heilman
‎2006 Aug 04 9:20 PM
Ok...it is nice to understand that ur prb is solved.
Regards
Anurag
‎2006 Aug 04 8:50 PM
Anurag,
But I need to replace both " and ', so '"' is fine and for the other `'` should work.
thanks
‎2006 Aug 04 9:51 PM
Rich,
In your example :
First one with out tild, if my character is '"This" aga'aah', its gives error.
‎2006 Aug 04 9:59 PM
‎2006 Aug 09 1:37 PM
Hi,
The literals can be assigned only
1)between 2 single Quotes or as you have explored
2)between 2 tildas,
eg: 'HIII SSSSS'.
or HIII SSSSS.
Now When u r assigning a string which contains single qoutes <b>(but not a pair of consecutive single qoutes )</b>say <HII' SS'> then the assignment is not possible by the first method as the compiler ont be able distinguish the actual end of the Assignment.It can be done by using the second method(As Rich had shown).
But When the string contains a pair of 2 consecutive single qoutes like <HI THIS IS ''SDN''>
then it can be done using the first Method.The actual data in the Variable will be then,
THIS IS 'SDN'.
If u use the second Method,the actual data will be
THIS IS ''SDN''.
The `` tells the compiler to consider the entire text as the contents.
Regards,
Samson
Message was edited by: Samson Moses