Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any FM that removes unwanted Zeroes in quantity Field.

0 Kudos

Requirement :

Input Output

100.00 100

100.123 100.123

100.250 100.25

1 ACCEPTED SOLUTION

DominikTylczyn
Active Contributor

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

7 REPLIES 7

michael_piesche
Active Contributor

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:

  • CONVERSION_EXIT_ZZQTY_OUTPUT
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.
  • CONVERSION_EXIT_ZZQTY_INPUT
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.

0 Kudos

Deleting trailing 0 could easily turn 100 into 1 if one is not careful. 🙂

0 Kudos

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 😉

DominikTylczyn
Active Contributor

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

This would work if number of decimals was fixed but in OP's example it could be anywhere between 0 and 3 decimals.

Jelena
Active Contributor

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.

0 Kudos

Thank you Everyone for your Valuable time 🙂