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

Former Member
0 Likes
658

hi folks,

I am reading a field value from a table into a variable that goes like '345-7890123<b>-</b>' there is this '-' after the number and need to remove it.

How can I use 'trim' here?

Thanks

Vinu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
641

REPLACE '-' WITH space

INTO field.

sasi

6 REPLIES 6
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
641



report zrich_0002
       no standard page heading.


data: s(30) type c value '132165451-'.


shift s right deleting trailing space.
shift s right deleting trailing '-'.
shift s left deleting leading space.


write:/ s.


Regards,

Rich Heilman

Message was edited by: Rich Heilman

Message was edited by: Rich Heilman

Read only

Former Member
0 Likes
642

REPLACE '-' WITH space

INTO field.

sasi

Read only

0 Likes
641

You could also do something like this.



report zrich_0002
       no standard page heading.


data: s(30) type c value '545132162-'.
data: x(30) type c.
data: offset type i.


offset = ( strlen( s ) - 1 ) .

x = s+0(offset).

write:/ s.
write:/ x.

Regards,

Rich Heilman

Read only

0 Likes
641

Hi

DATA: dir(40) VALUE '345-7890123-1'.

DO.

REPLACE '-' WITH space INTO dir.

IF sy-subrc <> 0. EXIT. ENDIF.

ENDDO.

CONDENSE dir no-gaps.

WRITE dir.

Max

Read only

0 Likes
641

Please make sure that you award points for all helpful answers and mark this post as "solved".

Regards,

Rich Heilman

Read only

Former Member
0 Likes
641

TRANSLATE variable USING '- '.

CONDENSE variable NO-GAPS.

Do you want to remove all the '-' or just the last one? If it is just the last one, then

v_len = STRLEN( variable ).

v_len = v_len -1.

variable = variable(v_len).