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: 

Trailing spaces after data

former_member215781
Active Participant
0 Kudos

Hi,

I have a requirement in my code where I need to keep trailing spaces after the value.

Say, the value is ABC with 2 spaces before ABC and 4 spaces after ABC.

' ABC '

I want to remove the spaces before ABC but want the spaces that exist after ABC.

Thanks,

Sim

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You can use SHIFT statement.

data: v_var type char6 value ' ABC '

SHIFT v_var LEFT DELETING LEADING space.

write:/ v_var.

Output will be ABC .

Regards,

Nikhil

5 REPLIES 5

Former Member
0 Kudos

Hi,

As per as ABAP goes simple Assignment operator or TRANSFER (to file) to truncate the spaces.

refer [this|; or you may need to WRITE EOL character Cl_ABAP_CHAR_UTILITIES=>CR_LF.

Hope this helps!

Regards

Shital

Former Member
0 Kudos

Hi,

Refer [Link|http://help.sap.com/saphelp_nw2004s/helpdata/en/79/c554d9b3dc11d5993800508b6b8b11/content.htm] on how to use CL_ABAP_CHAR_UTILITIES=>CR_LF (CRLF Carrige Return + Line Feed). You have to write CRLF at the end of your string to retain the trailing spaces.

Regards

Shital

Former Member
0 Kudos

Hi SIm,

Check this example for leading spaces --

SHIFT c BY n PLACES.

This command Shifts the contents of c by n places to the left. This statement has the same semantics as repeating the simple SHIFT statement n times.

Example

DATA: ALPHA1(10) TYPE C VALUE 'ABCDEFGHIJ',

ALPHA2 TYPE STRING,

FIVE TYPE I VALUE 5.

ALPHA2 = ALPHA1.

SHIFT ALPHA1 BY FIVE PLACES.

SHIFT ALPHA2 RIGHT BY 2 PLACES.

ALPHA1 now has the contents 'FGHIJ____ ' and ALPHA2 the contents '__ABCDEFGHIJ'.

To delete the spaces before

SHIFT c LEFT DELETING LEADING space.

Regards,

Pankaj

Edited by: Pankaj Singh on May 16, 2009 11:32 AM

Former Member
0 Kudos

Hi,

You can use SHIFT statement.

data: v_var type char6 value ' ABC '

SHIFT v_var LEFT DELETING LEADING space.

write:/ v_var.

Output will be ABC .

Regards,

Nikhil

0 Kudos

How do I remove both leading and training spaces from a statement. SHIFT LEFT is working fine....but SHIFT w_sameena LEFT DELETING LEADING '*' does not seem to work in my code.

The field value is ***ABCCDE*FGHI**JKL****

and I want the o/p as ABC*CDE*FGHI***JKL

Regards,

Sameena