Skip to Content
-2

Delete trailing characters at end of string

Jan 02 at 09:00 AM

89

avatar image
Former Member

hi,

i have a string which contains e.g. the values

1.00000

2.10000

12.20000

14.30277

now i want to remove the last 3 characters, so that the output is

1.00

2.10

12.20

14.30

how can i do it with an abap statement dynamicly ?

br Martin

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Matthew Billingham
Jan 02 at 09:33 AM
3

Use the string functions strlen and substring?

But from your example, it looks like you're wanting to get numbers to 2 decimal places, and your preferred solution is to drop the last 3 characters. Perhaps you should do something like

DATA number TYPE P LENGTH 8 DECIMALS 2.
number = string_representation_of_number.

It's usually a good idea to provide context with questions - what is the wider problem you're trying to resolve. While string slicing (or regex) might give you the answer, there may be a better way.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Happy New Year.

Since this is a forum for professionals, I expected the OP to know what he wants ;-)

1

I've been on this forum for too many years to be confident that's always the case!

2
Matthew Billingham

Ah, forgive the newby!

0
Horst Keller
Jan 02 at 09:14 AM
3

You can do that with a regular expression.

Create one that matches any number of characters followed by exactly three characters followed by the end of the word. Define the three characters as a group and replace that with an empty string.

Read the documentation to find out the syntax and use program DEMO_REGEX_TOY to experiment.

Share
10 |10000 characters needed characters left characters exceeded