Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Can we use "Find" instead of "REPLACE"

Former Member
0 Kudos

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).

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

6 REPLIES 6

Former Member
0 Kudos

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

Former Member
0 Kudos

hi,

do this way ...


data : v_char(20) value '100/100'

 translate v_char using '/*'.

write : v_char.
 

Regards,

Santosh

Former Member
0 Kudos

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

0 Kudos

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.

0 Kudos

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

Former Member
0 Kudos

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