Skip to Content
avatar image
-2
Former Member

Delete trailing characters at end of string

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Jan 02 at 09: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.

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 02 at 09: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.

    Add comment
    10|10000 characters needed characters exceeded