cancel
Showing results for 
Search instead for 
Did you mean: 

Changing decimal places of a number

Former Member
0 Kudos

I have to make some changes in the PO Script.

one of the change is to round off the figure of unit price to 3 decimal places instead of 2.

The command on the script for unit price is &IMP_UPRICE(C)&.when I am changing this to &IMP_UPRICE(3)&, it shows nothing on the document , just empty space.

How can i do that??

Regards,

Aisha Ishrat.

Accepted Solutions (0)

Answers (8)

Answers (8)

former_member480923
Active Contributor
0 Kudos

HI check the type of the field IMP_UPRICE is ithink it is a Character field so ur declration wont work, define a field of type QUAN inside the script and pass the value inside the variable. Print the variable using (.3) prefix.

This will work only if the number of original field has 3 decimals that is at the first place otherwise it will display 2 decimals that are avialble.

Hope that helps

Anirban M.

dev_parbutteea
Active Contributor
0 Kudos

Hi,

&IMP_UPRICE(3)&, means printing the first 3 characters in the variable!

So since IMP_UPRICE may be longer, it is displaying just first 3 characters .

What you need to do is write a perform for this translation like <b>(paying attention to the number of decimal places you need</b>):

/:PERFORM f_truncate_value in <b>PROGNAME</b>

/:USING &IMP_UPRICE&,

/:CHANGING &NEW_VARIABLE&

/:ENDPERFORM

Then display &NEW_VARIABLE& in place of &IMP_UPRICE&.

In se38, program <b>PROGNAME</b>

FORM f_truncate_value TABLES in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy.

FIELD-SYMBOLS: <fs_out_tab> TYPE itcsy.

DATA: p_ancien_kebtr(6) TYPE c,

p_nouveau_kbetr(5) TYPE c,

temp_kebtr1 TYPE n LENGTH 6,

temp_kebtr2 TYPE p LENGTH 5 DECIMALS 4,

temp_kebtr3 TYPE p LENGTH 4 DECIMALS 3.

READ TABLE in_tab INDEX 1.

IF sy-subrc EQ 0.

p_ancien_kebtr = in_tab2-value.

ENDIF.

MOVE p_ancien_kebtr TO temp_kebtr1.

temp_kebtr2 = temp_kebtr1 .

WRITE temp_kebtr2 TO p_nouveau_kbetr DECIMALS 3.

READ TABLE out_tab ASSIGNING <fs_out_tab> INDEX 1.

IF sy-subrc EQ 0.

<fs_out_tab>-value = p_nouveau_kbetr.

ENDIF.

ENDFORM. "F_TRUNCATE_VALUE

Regards,

Sooness.

Former Member
0 Kudos

Not working, its still showing 2 decimal places.

currently it is written as &IMP_UPRICE()& and it shows 2 decimal places.

Former Member
0 Kudos

I think you want &IMP_UPRICE(C.3)&.

Former Member
0 Kudos

not working

Former Member
0 Kudos

hi aisha,

just try like this,

go to T.code <b>su3</b>,

select <b>detaults</b> tab,

change the <b>decimal notation</b> according your requirement,

save.

it works.

regards,

seshu.

former_member196280
Active Contributor
0 Kudos

Try something like this &IMP_UPRICE(3.2)&.

regards,

SaiRam

Former Member
0 Kudos

Hi,

please go through this thread this may help you.

also go thru below

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

for more informaton above

http://wiki.ittoolbox.com/index.php/HOWTO:Sap_script

Regards

Shiva

Former Member
0 Kudos

&IMP_UPRICE(.2)&.

reward points if it is useful

Thanks

Seshu