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: 

Delete trailing characters at end of string

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

matt
Active Contributor

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.

5 REPLIES 5

horst_keller
Product and Topic Expert
Product and Topic Expert

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.

matt
Active Contributor

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.

horst_keller
Product and Topic Expert
Product and Topic Expert

Happy New Year.

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

matt
Active Contributor

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

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Ah, forgive the newby!