Skip to Content
avatar image
Former Member

Deleting trailing zeroes and decimal separator with String Templates

Can I use string templates to drop the trailing zeroes and, assuming there are no significant decimal numbers, the decimals separator?

As far as I know the way to do this in classic ABAP is either via SHIFT...DELETING or with the UNIT addition of the WRITE statement. I've found this related discussion on UNIT not having a string template equivalent and while I can see why that behaviour is too complex to add to string templates, I was hoping there was still a way to drop all non-significant trailing characters.

Can I do this with string templates or will I have to do it manually?

Example input > output:

231.0430   >  231.043
 21.1400   >   21.14
 78.050    >   78.05
158.4000   >  158.4
  7.00     >    7
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Aug 08, 2017 at 09:58 AM

    Convert the numbers to decfloats and use them as embedded expressions in string templates. The default output format of decfloats has no decimal separators and no trailing zeros. You can use the CONV operator for that.

    ... |{ CONV decfloat34( '231.0430' ) }| ...
    
    Add comment
    10|10000 characters needed characters exceeded