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: 

Removing excess space

0 Kudos
234

Hi ,

I have a field 'zxxx'.

In the program i have spl characters in between so

so i executed the following code

IF i_zpem-xxxxx CA '~!@#$%^&*()-:;/'.

REPLACE ALL OCCURRENCES OF REGEX '[ [:punct:] ]' IN I_Zpem-xxxx WITH ''.

ENDIF.

Its working fine but there is an extra space coming in at the end for some values

Ex : '23452sdfg '

'236767dfg'

'73452sdf87 '

'2345 2356' " note this is valid,space can be in the middle

so we cannot use condence because space in the middle is accepted so

how can we remove the space at the end.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
202

Hello,

You can use CONDENSE with NO-GAPS addition. This will supress the space even if it's in the middle of the string

Vikranth

8 REPLIES 8

Former Member
0 Kudos
203

Hello,

You can use CONDENSE with NO-GAPS addition. This will supress the space even if it's in the middle of the string

Vikranth

0 Kudos
202

Hi Vikranth ,

We cannot use CONDENCE with NOGAPS because space is accepted in middle for few fields

Ex: '2435 2456 5785' " it is a valid entry

'3455 3454 3423 ' " it is not a valid entry because there is extra space at the end.

0 Kudos
202

You can try this:

data: var1 type string value '3455 3454 3423 '.  " give space using Alt+255
data: len type i.

len = strlen( var1 ).
len = len - 1.

var1 = var1+0(len).

write:/ var1.

0 Kudos
202

Hi Mahesh

the out put length varies

ex:

'23453434 '

'2435 2456 5785'

'3455 3454 3423 '

'3455 3456 2567'

'3454677453 '

3678 4267 8545 '

the length varries so how can we implement this

0 Kudos
202

Since it is defined as variable, the above code works for any string length.

former_member387317
Active Contributor
0 Kudos
202

Hi Ravi Kiran,

Don't use NO-GAPS addition with CONDENCE just use only CONDENCE and it will work for you.

DATA: VAR1 TYPE STRING VALUE '3455 3454 3423 '. " Normal Space.. will not work if you do ALT+255
DATA: LEN TYPE I.

CONDENSE VAR1.

WRITE: / VAR1.

@ Mahesh,

Just for my curiosity can you explain me...

What's the difference between normal space and space (ALT + 255) ??

I am wondering why it behaves differently with these two things...

Hope it will solve your problem..

Thanks & Regards

ilesh 24x7

ilesh Nandaniya

0 Kudos
202

hi ravi ,

Declare like this ,

data : z(10) type c value '1234 56 ' .

data : k(10) type n .

data : m type i .

k = z .

m = i .

write m .

regards

Deepak .

0 Kudos
202

Thank u