Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write number with sign on the left and thousands separator point

Tags:

abap

I am holding the number in character format in abap. Because I have to take the minus from right to left. So I have to put the number to character and shift or using function 'CLOI_PUT_SIGN_IN_FRONT' I'm moving minus character to left.

But after assigning number to character it doesn't hold the points. I mean my number is;

  • 1.432- (as integer)
  • -1432 (as character)

I want;

  • -1.432 (as character)

is there a shortcut for this or should I append some string operations.

Edit:

Here is what I'm doing now.

data: mustbak_t(10) TYPE c,
      mustbak like zsomething-menge.

select single menge from zsomething into mustbak where something eq something.
mustbak_t = mustbak.

CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
  CHANGING
  VALUE         = mustbak_t.

write: mustbak_t.
like image 269
Mtok Avatar asked Apr 22 '13 07:04

Mtok


2 Answers

Here's another way, which i finally got working:

DATA: characters(18) TYPE c,
      ints TYPE i VALUE -222333444.

WRITE ints TO characters. "This is it... nothing more to say.

CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
  CHANGING
    value = characters.

WRITE characters.

Since integers are automatically printed with the thousands separator, you can simply output them to a char data object directly using WRITE TO with no aditions..... lol

like image 40
vlad-ardelean Avatar answered Sep 20 '22 17:09

vlad-ardelean


If you're on a recent release, you could use string templates - you'll have to add some black magic to use a country that confoirms to your decimal settings, though:

DATA: l_country TYPE t005x-land,
      l_text    TYPE c LENGTH 15,
      l_num     TYPE p LENGTH 6.

SELECT SINGLE land
  INTO l_country
  FROM t005x
  WHERE xdezp = space.

l_num = '-123456'.
l_text = |{ l_num COUNTRY = l_country }|.

WRITE: / l_text.

In this case, you need a country code to pass to the COUNTRY parameter as described in the format options. The values of the individual fields, namely T005X-XDEZP are described in detail in the country-specific formats.

tl;dr = Find any country where they use "." as a thousands separator and "," as a decimal separator and use that country settings to format the number.


You could also use classic formatting templates, but they are hard to handle unless you have a fixed-length output value:

DATA: l_text TYPE c LENGTH 15,
      l_num  TYPE p LENGTH 6 DECIMALS 2.

l_num = '-1234.56'.
WRITE l_num TO l_text USING EDIT MASK 'RRV________.__'.
CONDENSE l_text NO-GAPS.

WRITE: / l_text.
like image 144
vwegert Avatar answered Sep 16 '22 17:09

vwegert