04-10-2008 1:11 PM
Hi Friends
Can I use "find" command in the below mention code to improve the performance of the code. Now it is giving dump.
One of my friend suggested to change the "replace" command with "find" command. Is it posssible? If yes please specify how to use? Thanks!
REPLACE '\"' WITH '^' into p_table_text(structure).
04-12-2008 1:39 AM
Hello Amminesh,
Additionally I will provide you with the following trick, solving your replacement from '\"' to ' " '. Using my before shown solution doesn't cover the trailing SPACE. To achieve this, the BYTE MODE has to be chosen. Here is a simple example:
data: text(64) type c value 'abc\"def\"ghij'.
data: xfield(2) type X value '5C22'. "==\"
data: xfield2(3) type X value '202220'. "==' " '"
field-symbols: <hex> type x.
assign text to <hex> casting.
Write: / 'Before', text.
replace all occurrences of xfield in <hex> with xfield2 in byte mode.
write: / 'After', text.
Implement is. You can omit your entire IF-block. In case there is no \" in your text, the replacement doesn't do anything and it returns SY-SUBRC = 4.
Please let me know if this solution works for you.
Have fun,
Heinz
04-10-2008 1:15 PM
Hi,
FIND is a to search for something in a string.
REPLACE is more advanced and its job is to FIND and then REPLACE it with something else.
Regards,
Satish
04-10-2008 1:19 PM
hi,
do this way ...
data : v_char(20) value '100/100'
translate v_char using '/*'.
write : v_char.
Regards,
Santosh
04-11-2008 5:37 AM
Hello Amminesh,
the REPLACE-statement is an obsolete statement and shouldn't be used anymore. Instead use TRANSFER or - when you only want to know if there is a specific character in your string (or record) - use one of the logical IF expressions:
IF searchstring {CO | CN | CA | NA | CS | NS | CS | NP} searchfor.
.....
endif.
Hope this helps,
Heinz
04-11-2008 12:54 PM
Hi Heinz
Thanks for the information Please suggest how to use the transfer command in the place of "Replace" in below code.
If p_tbl_ text-line ca '\" .
While p_tbl_text-line ca '\" .
REPLACE '\" WITH '^' into p_tbl_text-line.
end while.
While p_tbl_text-line ca '^'.
REPLACE '^' WITH ' " ' INTO p_tbl_text-line.
endwhile.
Endif.
Thanks
Amminesh.
04-11-2008 8:10 PM
Hello Amminesh,
Sorry. I mistyped it. I meant TRANSLATE!! This is also an obsolete statement and can not be used in Unicode!
My suggestion: Use the new REPLACE-statement (new variant since version 6.10)
REPLACE [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF] pattern
IN [section_of] dobj WITH new
[IN {BYTE|CHARACTER} MODE]
[{RESPECTING|IGNORING} CASE]
[REPLACEMENT COUNT rcnt]
{ {[REPLACEMENT OFFSET roff]
[REPLACEMENT LENGTH rlen]}
| [RESULTS result_tab|result_wa] }.
In your case simply
data: field1 type string value 'ab\"cde\"efg'.
replace all occurrences of '\"' in field1 with '^'.
write: / field1.
No WHILE cycle is needed when using ALL OCCURRENCES.
Try it,
Heinz
04-12-2008 1:39 AM
Hello Amminesh,
Additionally I will provide you with the following trick, solving your replacement from '\"' to ' " '. Using my before shown solution doesn't cover the trailing SPACE. To achieve this, the BYTE MODE has to be chosen. Here is a simple example:
data: text(64) type c value 'abc\"def\"ghij'.
data: xfield(2) type X value '5C22'. "==\"
data: xfield2(3) type X value '202220'. "==' " '"
field-symbols: <hex> type x.
assign text to <hex> casting.
Write: / 'Before', text.
replace all occurrences of xfield in <hex> with xfield2 in byte mode.
write: / 'After', text.
Implement is. You can omit your entire IF-block. In case there is no \" in your text, the replacement doesn't do anything and it returns SY-SUBRC = 4.
Please let me know if this solution works for you.
Have fun,
Heinz