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

ABAP Trim Statement

Former Member
0 Likes
5,251

hi,

Have an issue where special characters you can't see via se16 are at the end of a character field. I need a way to strip them off via abap. Is there a good way to do this? New to abap, so be gentle. Have tried about everything including shift. Is there a trim command that can be used?

Thanks in advance.

2 REPLIES 2
Read only

Former Member
0 Likes
1,960

HI,

The VB "trim" sentence is CONDENSE in ABAP. But CONDENSE drops all spaces before and after the string. I think you are looking for something like mid$, Left$ or Right$ (in VB again).

You can use substrings to do that, like

Code:

DATA: chars TYPE I.

chars = strlen( yourstring ) - 1.

IF yourstring+chars = yourspecialchar.

yourstring = yourstring(chars).

ENDIF.

That mini-code sample takes the lenght of your string (minus the last character), and checks that last character. If that last one is the special one you are trying to drop, the sentence between IF-ENDIF drops it.

Substrings are used like

Code:

string+pos1(pos2)

where pos1 is the amount of characters displaced from the beguinning and pos2 the number of characters taken.

IE: string+pos1(pos2) would be the same than VB's Mid$(string, pos1, pos2)

Wish it helps,

Cheers,

Chandra Sekhar.

Read only

Former Member
0 Likes
1,960

Just for correctness

in ABAP

fieldn(m) extracts m characters starting from the the character at position n1

e.g. if field contains the string 'ABCDEFG' the statement field+2(3) returns the string 'CDE'

in VB

the statement Mid$(string,n,m) extracts m characters starting from the n-th character,

e.g. if string is 'ABCDEFG' the statement Mid$(string,2,3) returns the string 'BCD'.

Bye, Antonino