Application Development and Automation 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: 
Read only

Remove Zeros

Former Member
0 Likes
2,370

Is there any function module i can use to remove zeros in a dec field.

For example

I need to convert 12.300 to 12.3

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,885
Hi Jose,

 you can do one way..but you need to move the decimal value to a character value, not sure if it suits ur requirement

REPORT  ychatest.

DATA : v_dec TYPE p DECIMALS 3 VALUE '12.300',
       v_char(20).

WRITE v_dec TO v_char.

CALL FUNCTION 'FTR_CORR_SWIFT_DELETE_ENDZERO'
  CHANGING
    c_value = v_char.

WRITE : / v_char.
10 REPLIES 10
Read only

Former Member
0 Likes
1,885

Hi,

Declare decimal places 1 and convert it.

Reward if useful!

Read only

0 Likes
1,885

Yes but for example i can have:

12,210 and i need to convet it to 12.21

I don't know the number of decimal places.

Read only

Former Member
0 Likes
1,885

Move the decimal value to a character field and use the SHIFT RIGHT statement.

data gv_value(15).

gv_value = gv_dec.

shift right gv_value deleting trailing '0'.

Read only

Former Member
0 Likes
1,885

create another variable of type P.

assign to that variable.

when you write the value use "UPTO TO 2 DECIMAL".

Read only

Former Member
0 Likes
1,885

hi,

U can use the function module 'CONVERSION_EXIT_ALPHA_OUTPUT'.

this would remove leading zeroes

Reward points if useful

Regards

Ashu

Read only

Former Member
0 Likes
1,885

Hi,

You may use the option

field(.0) for printing the quantity

field(.2) for printing the amount..

Go through SAP help given below..

Number of Decimal Places

A program symbol of one of the data types DEC, QUAN, and FLTP can contain decimal place data. Use the option below to override the Dictionary definition for the number of decimal places for the formatting of this symbol value.

Syntax

&symbol(.N)&

The EKPO-MENGE field contains the value 1234.56. The Dictionary definition specifies 3 decimal places and an output length of 17.

&EKPO-MENGE& -> 1,234.560

&EKPO-MENGE(.1) -> 1,234.6

&EKPO-MENGE&(.4) -> 1,234.5600

&EKPO-MENGE&(.0) -> 1,235

Read only

Former Member
0 Likes
1,885

use this function module:-

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

INPUT = COMM_STRUCTURE-zcustomer

IMPORTING

OUTPUT = RESULT

Or u can use this FM also:-

ZSOLD_TO

rewards point if useful....

Thanks....

Abhay

Read only

Former Member
0 Likes
1,886
Hi Jose,

 you can do one way..but you need to move the decimal value to a character value, not sure if it suits ur requirement

REPORT  ychatest.

DATA : v_dec TYPE p DECIMALS 3 VALUE '12.300',
       v_char(20).

WRITE v_dec TO v_char.

CALL FUNCTION 'FTR_CORR_SWIFT_DELETE_ENDZERO'
  CHANGING
    c_value = v_char.

WRITE : / v_char.
Read only

Former Member
0 Likes
1,885

simply use "DATA pack TYPE p DECIMALS 4 VALUE '1234.5678'."

or "WRITE pack DECIMALS 2"

Read only

Former Member
0 Likes
1,885

Hello,

[code]

DATA:

L_MENGE_P5(16) TYPE P DECIMALS 5,

L_MENGE_P3(16) TYPE P DECIMALS 2,

L_ANDEC like T006-ANDEC value 2.

L_MENGE_P5 = '56.42000'.

CALL FUNCTION 'ROUND'

EXPORTING

DECIMALS = L_ANDEC

input = L_MENGE_P5 "over here u need to pass other than char

SIGN = '+'

IMPORTING

OUTPUT = L_MENGE_P3

EXCEPTIONS

INPUT_INVALID = 1

OVERFLOW = 2

TYPE_INVALID = 3

OTHERS = 4

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WRITE:/ L_MENGE_P3.

/code]

Regards,

Deepu.K