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: 

string trim

Former Member
0 Kudos
17,767

hi

Is there is any trim function for the string ?

want to remove the starting and ending spaces of string

thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos
2,807

DATA: ld_field(50) type c.

P_field type ld_field.

p_field = ' Welcome '.

ld_field = p_field.

CONDENSE ld_field .

write ld_field .

It is displying the like 'Welcome '

Is it because that i have specify the ld_field(50) so it is thinking that it is 50 char length and

just appeding the spaces after 'Wlecome '

11 REPLIES 11

anversha_s
Active Contributor
0 Kudos
2,807

hi,

just use

<b>CONDENSE</b>

eg:

*Code to demonstrate CONDENSE command

DATA: ld_field(50) type c.

p_field = ' Welcome '.

CONDENSE p_field. "P_field must be of type character

*Result of p_field would be: 'Welcome'

rgds

Anver

<b><i>if hlped pls mark points</i></b>

<i>if your issue solved , kindly close the thread</i>

0 Kudos
2,807

Hi,

did your issue solve.

if not kindly revert back.

Rgds

Anver

Former Member
0 Kudos
2,807

use CONDENSE

or

u can use SHIFT command also

shift v_var left deleting leading space.

shift v_var right deleting tailing pace.

Former Member
0 Kudos
2,808

DATA: ld_field(50) type c.

P_field type ld_field.

p_field = ' Welcome '.

ld_field = p_field.

CONDENSE ld_field .

write ld_field .

It is displying the like 'Welcome '

Is it because that i have specify the ld_field(50) so it is thinking that it is 50 char length and

just appeding the spaces after 'Wlecome '

0 Kudos
2,807

hi,

use <b>NO-GAPS</b>

DATA: ld_field(50) type c.

P_field type ld_field.

p_field = ' Welcome '.

ld_field = p_field.

CONDENSE ld_field <b>NO-GAPS</b>.

write ld_field .

rgds

Anver

Former Member
0 Kudos
2,807

<b>Your problem has been solved in this thread,</b>

Regards

Kathirvel

Former Member
0 Kudos
2,807

thanks for the quick reply

I have tried NO-GAPS It works.. but it is removeing all the spaces in the string and i want to remove only the

left side sapces and right side sapces .

e.g

DATA: ld_field(50) type c.

P_field type ld_field.

p_field = ' Welcome To SAP '.

ld_field = p_field.

CONDENSE ld_field NO-GAPS.

write ld_field .

The out put is

'WlecomeToSAP'

Regards

mahya

0 Kudos
2,807

hi,

then use this.

<b>

SHIFT ld_field RIGHT DELETING TRAILING SPACE.

SHIFT ld_field LEFT DELETING LEADING SPACE.</b>

DATA: ld_field(50) type c.

P_field type ld_field.

p_field = ' Welcome To SAP '.

ld_field = p_field.

SHIFT ld_field RIGHT DELETING TRAILING SPACE.

SHIFT ld_field LEFT DELETING LEADING SPACE.

write ld_field .

rgds

Anver

Former Member
0 Kudos
2,807

there is no trim function as java in ABAP.

use the condense statement to remove the spaces.

Former Member
0 Kudos
2,807

<b>I have posted the solution exactly what you wanted already. Please check that.</b>

Regards

Kathirvel

Former Member
0 Kudos
2,807

Points rewarded !!

Thanks a lot everyone for help!