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: 

Replace '|' with Space

kamesh_g
Contributor

HI

I should replace ' | ' with space .

I am using 'Replacing all occurances ' but its not replacing with space .

please give inputs on this

thanks

kamesh

1 ACCEPTED SOLUTION

brad_bohn
Active Contributor
0 Kudos

What does your code (and your string) look like? It helps when you post it...

The statement works just fine for pipes and so does TRANSLATE...though the gaps will be handled differently.

8 REPLIES 8

brad_bohn
Active Contributor
0 Kudos

What does your code (and your string) look like? It helps when you post it...

The statement works just fine for pipes and so does TRANSLATE...though the gaps will be handled differently.

0 Kudos

HI brad

I have one text field like . 'This| is|test |Program ' .

I want this like 'This is test program '. For this I am using REPLACE ALL OCCURANCES OF ' | ' in field with ' ' .

But its not giving space but removing |. This is my issue .I think ou understood .

How TRANSLATE statement will help in this .

Thanks

kamesh

Edited by: KAMESH G on Oct 28, 2010 7:37 PM

Former Member
0 Kudos

REPLACE doesn't work well when replacing with a space. Use TRANSLATE instead:

DATA: f1(10) VALUE '1234|567|8'.
TRANSLATE f1 USING '| '.

Rob

Former Member
0 Kudos

Try this code


DATA lv_data TYPE char20 VALUE 'This|test |is for SDN | '.

WRITE 😕 lv_data.
REPLACE ALL OCCURRENCES OF '|' IN lv_data WITH ' '.
WRITE 😕 lv_data.

Former Member
0 Kudos

I think this code works the same as the original.

Regular expressions are another option. You can search the forum for examples.

Rob

MarcinPciak
Active Contributor

From help.sap.com:

Character literals are sequences of alphanumeric characters in the source code of an ABAP program enclosed in single quotation marks or backquotes. Character literals enclosed in quotation marks have the predefined ABAP type c and are described as text field literals. Literals enclosed in backquotes have the ABAP type string and are described as string literals. The field length is defined by the number of characters. With text field literals trailing blanks are ignored while in string literals they are taken into account.

So in your case you need to use string literal which is represented by backquotes `


REPLACE ALL OCCURRENCES OF '|' IN lv_data WITH ` `.

Now it will work

Regards

Marcin

0 Kudos
Does anyone know why this doesn't work?
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>newline IN lv_text WITH ` `.
The newlines simply get removed and no space replaces them.

0 Kudos

Use the below if you want to convert '_' with space.

TRANSLATE lv_text USING '_  '.