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

Replace '|' with Space

kamesh_g
Contributor
11,103

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
Read only

brad_bohn
Active Contributor
0 Likes
6,366

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
Read only

brad_bohn
Active Contributor
0 Likes
6,367

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.

Read only

0 Likes
6,366

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

Read only

Former Member
0 Likes
6,366

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

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

Rob

Read only

Former Member
0 Likes
6,366

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.

Read only

Former Member
0 Likes
6,366

I think this code works the same as the original.

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

Rob

Read only

MarcinPciak
Active Contributor
6,366

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

Read only

0 Likes
6,366
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.
Read only

0 Likes
6,366

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

TRANSLATE lv_text USING '_  '.