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: 

How to replace space in records

Former Member
0 Kudos
493

Hi All,

My records are in one variable with charecter 200, i want to replace space by %20. How do i do this....

Reg,

Suren

1 ACCEPTED SOLUTION

valter_oliveira
Active Contributor
0 Kudos
204

DATA: pref TYPE char3 VALUE '%20'.
DATA: aux TYPE char1 VALUE '#'.
TRANSLATE <your_var> USING ' #'.
REPLACE ALL OCCURRENCES OF aux IN <your_var> WITH pref.

Regards,

Valter Oliveira.

8 REPLIES 8

valter_oliveira
Active Contributor
0 Kudos
205

DATA: pref TYPE char3 VALUE '%20'.
DATA: aux TYPE char1 VALUE '#'.
TRANSLATE <your_var> USING ' #'.
REPLACE ALL OCCURRENCES OF aux IN <your_var> WITH pref.

Regards,

Valter Oliveira.

Former Member
0 Kudos
204

hi,

use replace for all occurences of that varibale with %20.

syntax is like this.

Replace for all occurances of space in variable with '%20'.

0 Kudos
204

Hi Subas,

Syntax is showing an error, will appreciate if you can provide me the right Syntax.

Rg,

Suren

Edited by: Suren on Sep 22, 2008 7:44 AM

0 Kudos
204

Hi Suren,

What is the error u r getting?

Valter's solution given above is working fine.

Regards,

Surinder

0 Kudos
204

Hi,

for all who seached the solution of the problem in this diskussion like me:

The solution is in first answer of Valter Oliveira.

First translate spaces to sharps and then replace sharps by '%20'.

Direct replace of spaces is not possible, cause only spaces are recognized as empty string, and the result is an infinite loop.

You have only a problem, if you use sharps in your source string ;-(

Regards

Christoph

Former Member
0 Kudos
204

Suren...

Can you come again with ur ques...Just do u want to eliminate spaces...

Exam "sldjfl slkdjsl sakljkldj slkdjls sdljkkl sdljlj ",

result must be "sdkljdflsjaddjlsjjldjlsjljdlsjldjs"

What is ur exact requirement

Thanks

0 Kudos
204

Hi, Santosh

Exam "sldjfl slkdjsl sakljkldj slkdjls sdljkkl sdljlj ",

Result Wanted : sldjfl%20slkdjsl%20sakljkldj%20slkdjls%20sdljkkl%20sdljlj ",

Ashoak Narayandas Advani

former_member194797
Active Contributor
0 Kudos
204

Hi,

I suppose you have not to translate the trailing spaces.

(if you translate the trailing spaces, you have a risk to truncate %20 as %2 or %).

So I should propose this:


data: text(30) value 'this is a test                '.
data: wwlen type i.

write: / text.
wwlen = strlen( text ).
replace all occurrences of ` ` 
in SECTION OFFSET 0 LENGTH wwlen OF text with '%20'.
* CAUTION: use ` ` and not ' ' 
write: / text.