01-02-2018 9:00 AM
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
01-02-2018 9:33 AM
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.
01-02-2018 9:14 AM
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.
01-02-2018 9:33 AM
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.
01-02-2018 9:50 AM
Happy New Year.
Since this is a forum for professionals, I expected the OP to know what he wants 😉
01-02-2018 12:48 PM
I've been on this forum for too many years to be confident that's always the case!
01-02-2018 2:02 PM