Application Development and Automation 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: 
Read only

Duda with REPLACE ALL OCCURRENCES

Former Member
0 Likes
2,259

Hello! Exists the posibility of optimize the next code?

REPLACE ALL OCCURRENCES OF 'á' IN wa_header-justif WITH 'á'.

REPLACE ALL OCCURRENCES OF 'é' IN wa_header-justif WITH 'é'.

REPLACE ALL OCCURRENCES OF 'í' IN wa_header-justif WITH 'í'.

REPLACE ALL OCCURRENCES OF 'ó' IN wa_header-justif WITH 'ó'.

REPLACE ALL OCCURRENCES OF 'ú' IN wa_header-justif WITH 'ú'.

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
1,777

Try with Regex - [áéíóú] and replacement á.

Use program DEMO_REGEX_TOY to play with it.

If the input text is -


Thís hás sómé néw stúff

Output would be (with replace all)

Thás hás sámá náw stáff 

Regards,
Naimesh Patel

Try with Regex - [áéíóú] and replacement á.

Use program DEMO_REGEX_TOY to play with it.

If the input text is -


Thís hás sómé néw stúff

Output would be (with replace all)

Thás hás sámá náw stáff 

Regards,
Naimesh Patel

8 REPLIES 8
Read only

naimesh_patel
Active Contributor
0 Likes
1,778

Try with Regex - [áéíóú] and replacement á.

Use program DEMO_REGEX_TOY to play with it.

If the input text is -


Thís hás sómé néw stúff

Output would be (with replace all)

Thás hás sámá náw stáff 

Regards,
Naimesh Patel

Read only

0 Likes
1,777

Thanks! but, How I can use this in my code ABAP?

Read only

0 Likes
1,777

Simplest form - REPLACE ALL OCCURRENCES OF REGEX 'u*' IN text WITH 'x'

http://help.sap.com/abapdocu_740/en/abapreplace_in_pattern.htm#!ABAP_ADDITION_1@1@

Regards,

Naimesh Patel

Read only

0 Likes
1,777

Thaks, I can put multiple values in WITH 'x'?

Read only

0 Likes
1,777

Yes. You need to put as many characters as you want.

Read only

0 Likes
1,777

Thanks! Like:<br>

REPLACE ALL OCCURRENCES OF REGEX 'áéíóú' IN my_var WITH 'param1' 'param2' 'param3...?

Read only

Former Member
0 Likes
1,777

Since you want to work on the same field a lot, I'd suggest a local macro (this is an example where a macro makes sense):

define m_rep.

REPLACE ALL OCCURRENCES OF &2 IN &1 WITH &3.

end-of-definition.

(note the sequence of placeholders)


Now you can code like so.


m_rep fieldname:

'from1' 'to1',

'from2' 'to2',

'from3' 'to3'.


With proper naming and indentation, it makes your code more readable. The performance is the same of course... Keep the macro close to the code if possible.


If the action is more complex and you need to debug, you can use the same technique for readability and issue a perform from the macro. I only use macros for some cases, and this would be one of them.


Wolfgang


Read only

matt
Active Contributor
0 Likes
1,777

These are HTML tags. I'm fairly sure there are some standard function modules or methods that do this work for you. Or perhaps the escape string function (7.40).