02-06-2020 12:59 PM
Requirement :
Input Output
100.00 100
100.123 100.123
100.250 100.25
02-06-2020 3:32 PM
You could use just a simple WRITE statement with DECIMALS 0 addition - see SAP Help on WRITE format options: WRITE - int_format_options
An example from SAP Help:
DATA: pack TYPE p LENGTH 8 DECIMALS 4 VALUE '1234.5678',
formatted_text TYPE c LENGTH 10.
WRITE pack TO formatted_text NO-GROUPING DECIMALS 2.
cl_demo_output=>display_text( formatted_text ).
The formatted result of "1234.5678" is "1234,57".
HTH
Dominik Tylczynski
02-06-2020 2:55 PM
So you want to do this why? Is it more readable?
If it is a Z-Field, you could easily implement a conversion exit e.g. ZZQTY and assign this conversion exit to the domain of your data element. The following codings are by far not complete, as you probably would also have to take user settings regarding the display of numbers into account. Its quick and dirty, but you might get the idea.
You would have to implement two functions:
FUNCTION conversion_exit_zzqty_output.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(INPUT)
*" EXPORTING
*" VALUE(OUTPUT)
*"----------------------------------------------------------------------
output = input.
SHIFT output RIGHT DELETING TRAILING ' '.
SHIFT output RIGHT DELETING TRAILING '0'.
SHIFT output RIGHT DELETING TRAILING '.'.
ENDFUNCTION.
FUNCTION conversion_exit_zzqty_input.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(INPUT)
*" EXPORTING
*" VALUE(OUTPUT)
*"----------------------------------------------------------------------
DATA: lv_qty TYPE zquantity.
TRY .
lv_qty = input.
output = lv_qty.
CATCH cx_root.
CLEAR output.
ENDTRY.
ENDFUNCTION.
If it is a standard field and a standard program, I would seriously reconsider this request, and probaby rather try to modify the screen output rather than the domain, but this would be a lot more work though.
02-06-2020 10:13 PM
Deleting trailing 0 could easily turn 100 into 1 if one is not careful. 🙂
02-07-2020 3:43 AM
Deleting trailing 0 will always turn 100 in 1, when dealing with character (eg syntax error with integer or dump if type is only known at runtime).
The assumption is, as in the proposed question, that the value is passed from a number type with decimals. So of course you have to be careful and know what you are doing 😉
02-06-2020 3:32 PM
You could use just a simple WRITE statement with DECIMALS 0 addition - see SAP Help on WRITE format options: WRITE - int_format_options
An example from SAP Help:
DATA: pack TYPE p LENGTH 8 DECIMALS 4 VALUE '1234.5678',
formatted_text TYPE c LENGTH 10.
WRITE pack TO formatted_text NO-GROUPING DECIMALS 2.
cl_demo_output=>display_text( formatted_text ).
The formatted result of "1234.5678" is "1234,57".
HTH
Dominik Tylczynski
02-06-2020 10:18 PM
This would work if number of decimals was fixed but in OP's example it could be anywhere between 0 and 3 decimals.
02-06-2020 10:33 PM
Have you tried searching in Google? Google -> "remove trailing 0 site:sap.com" finds 4k+ hits and the first page is full top to bottom with the SCN posts asking the same question.
Some of the old answers mention FM FTR_CORR_SWIFT_DELETE_ENDZERO. It's not released to the customers and converts "100.00" into "100." instead of "100". But it only has a few lines of code, so it shouldn't be difficult to build on that and create your own utility method.
04-02-2020 12:00 PM
Thank you Everyone for your Valuable time 🙂