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: 

Remove the values afetr two decimal points...

Former Member
0 Kudos
2,048

hi all,

am doing SD form..in tat i used my own logic to get totals sub-totals, tax and discount....output data s showing correctly...but it displaying more than two decimal points....for some values it showing correctly...

eg.

i want like this.....100.89

but it s showing like this 100.897...i declare it as string.....

can u guide me in this...

22 REPLIES 22

Former Member
0 Kudos
669

sorry for before question small mistake...not to remove have to round off....i declare all this as type STRING..

am getting output like this....

dis count = 32.75.

sub-total = 622.27

add gst = 43.5575.

total = 665.8075.

but my orginal output is like this...

dis count = 32.75.

sub-total = 622.27

add gst = 43.56.

total = 665.81.

0 Kudos
669

In the script write the number of decimals in ( ) and it automatically rounds in display &sub_total10(2)&

0 Kudos
669

HI JOY....

Could u please give me in detail if u don mind....

0 Kudos
669

In the script program layout set.. check where the values are getting printed... SE71 > form name > windows....

some where in the code you will find variables in & .....& there change the variables as I mentioned before....

the value in brackets will decide the number of decimals to show.. and rounding will automatically taken care..

0 Kudos
669

Hi,

Declare the variables as type p decimals 2.

Regards,

Soumya.

0 Kudos
669

if i write this in script .....

&sub_total(2)& ....like this it is printing the same &sub_total(2)& not value...

This would happen if sub_total is either not declared or does nt receieve values properly from callg report

Jus check it

former_member228751
Contributor
0 Kudos
669

Hi Sai,

dis_count = 32.75.

sub_total = 622.27

add_gst = 43.5575.

total = 665.8075.

If u want write this in script, then write them in &....(n)& format.

E.g.


&dis_count(2)&   &sub_total(2)&   &add_gst(2)&   &total(2)&

Its output will be:

32.75 622.27 43.56 665.81

It will be rounded off two decimals automatically in this way.

Regards,

Sachin

0 Kudos
669

hi

actually am doing calculatipon in sub routine....from sub routine am passing the values to script.....

guided me in this...can u plls tell me how to declare in script or in sub routine...

0 Kudos
669

if i write this in script .....

&sub_total(2)& ....like this it is printing the same &sub_total(2)& not value...

0 Kudos
669

Hello Sai,

if you want the nearest value, just declare a variable with type 'P' 0 decimals, and move the value to this variable then automically it will get rounded off to its nearest value.

eg: data : gv1 type string value '5.585',

gv2 type p decimals 0.

gv2 = gv1.

write : gv2.

output: 6

Hope it helps!!

Regards,

Pavan

Former Member
0 Kudos
669

Hi sai,

A program symbol can contain decimal place data. The option below overrides the Dictionary definition for the number of decimal places to format this symbol value.

Syntax:


&symbol(.n)&

I think this will help you out if number of decimal places have to be set


&sub_total& ---------------> 1,234.560 
&sub_total(.1)&------------>1,234.6 
&sub_total(.4)&------------->1,234.5600 
&sub_total(0)&---------------> 1,235

if the problem still persists post back.

Regards,

K.SIbi

Edited by: sibi k kanagaraj on Mar 20, 2009 5:46 AM

Edited by: sibi k kanagaraj on Mar 20, 2009 5:47 AM

Edited by: sibi k kanagaraj on Mar 20, 2009 5:48 AM

0 Kudos
669

hi ,

if i give like this in layout...

&sub_total(.1)&...the output contains the same one....its not printing the value......

i have assign like this in layout...&subtot(.2)&.....the output also same....

ACTUALLY AM GETTING THE OUTPUT LIE THIS...

discount = 10.00

subtotal = 450.00

GST = 62.5661 ACTUAL IS: 62.57

tOTAL = 665.8075 aCTUAL ONE IS: 665.81

BUT I WANT LIKE THIS..I CANT DECLARE DECIMALS BECAUSE CURRENCY KEYS CANNOT BE CONVERTED TO DECIMALS....

0 Kudos
669

Hi

How have you declared sub_total and how do u pass it to the form ?

Can you send the code ?

0 Kudos
669

hi this s the coding...

/: PERFORM SUB_TOTAL IN PROGRAM ZSD_CASH_ADDRESS

/: USING &KOMK-SUPOS(I13)&

/: USING &KOMVD-KBETR&

/: USING &KOMVD-KWERT&

/: USING &KOMK-FKWRT&

/: CHANGING &SUBTOT&

/: CHANGING &DISAMO&

/: CHANGING &LV_GST&

/: CHANGING &LV_TOTAL&

/: ENDPERFORM

SU

/ ,,,,,,,,,,,,,, <B>DISCOUNT</>,, &DISAMO(I13)&

/*

SU ,,,,,,,,,,,,,, <B>SUB-TOTAL</>,, &SUBTOT(I13)&

/ ,,,,,,,,,,,,,, <B>ADD GST(@7%)</>,, &LV_GST(I13)&

/ ,,,,,,,,,,,,,, <B>TOTAL</>,, &LV_TOTAL(I13)&

FORM SUB_TOTAL TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

"tables:vbpa.

DATA : LV_TOT LIKE KOMK-SUPOS,

LV_DIS LIKE KOMK-SUPOS.

"LV_STO LIKE KOMK-SUPOS,

"LV_DAM LIKE KOMK-SUPOS.

DATA: LV_STO TYPE STRING,

LV_DAM TYPE STRING,

LV_GST TYPE STRING,

LV_TOTAL TYPE STRING,

LV_KBETR TYPE KBETR,

LV_LEN TYPE I,

LVS_KBETR TYPE KBETR.

DATA: LKWERT_TOTAL LIKE KOMV-KWERT.

DATA: L_NAME TYPE TDOBNAME,

LTW_LINES TYPE TLINE,

L_VALUE TYPE CHAR255,

LV_KNUMV TYPE KNUMV,

L_VBELN TYPE VBELN.

DATA:P_VBELN TYPE VBAK-VBELN.

SELECT SINGLE KNUMV FROM VBAK INTO LV_KNUMV WHERE VBELN = T_VBELN.

SELECT SINGLE KBETR FROM KONV INTO LV_KBETR WHERE KNUMV = LV_KNUMV AND KSCHL EQ 'MWST'.

SELECT SINGLE KBETR FROM KONV INTO LVS_KBETR WHERE KNUMV = LV_KNUMV AND KSCHL EQ 'RA00' AND KOAID EQ 'A'.

"Get the value of sub-total

READ TABLE IN_TAB WITH KEY 'KOMK-SUPOS'.

IF IN_TAB-VALUE IS NOT INITIAL.

CONDENSE IN_TAB-VALUE NO-GAPS.

CALL FUNCTION 'BKK_AMOUNT_STRING_CONVERT'

EXPORTING

AMOUNT_STRING = IN_TAB-VALUE

DCPFM = 'X'

WAERS = 'SGD'

IMPORTING

AMOUNT = LKWERT_TOTAL.

ENDIF.

MOVE LKWERT_TOTAL TO LV_TOT.

CLEAR : LKWERT_TOTAL.

*Get the value of Discount

"get the gst value

READ TABLE IN_TAB WITH KEY 'KOMK-FKWRT'.

IF IN_TAB-VALUE IS NOT INITIAL.

CONDENSE IN_TAB-VALUE NO-GAPS.

CALL FUNCTION 'BKK_AMOUNT_STRING_CONVERT'

EXPORTING

AMOUNT_STRING = IN_TAB-VALUE

DCPFM = 'X'

WAERS = 'SGD'

IMPORTING

AMOUNT = LKWERT_TOTAL.

ENDIF.

MOVE LKWERT_TOTAL TO LV_TOTAL.

"write lv_total to lv_total decimals 2.

CLEAR : LKWERT_TOTAL.

DATA: LV_TOT1 TYPE STRING.

"LV_DIS = 10.

"if lv_dis ne ''.

IF LVS_KBETR NE '0.00'.

LVS_KBETR = LVS_KBETR / 10.

LV_TOT1 = ( LV_TOT * 100 ) / ( 100 + LVS_KBETR ).

LV_DAM = LV_TOT1 - LV_TOT.

"endif.

LV_STO = LV_TOT1 - LV_DAM.

ELSE.

LV_STO = LV_TOT.

ENDIF.

LV_GST = LV_STO * LV_KBETR / ( 100 * 10 ).

LV_TOTAL = LV_STO + LV_GST.

READ TABLE OUT_TAB WITH KEY 'SUBTOT'.

CLEAR OUT_TAB-VALUE.

CONDENSE LV_STO NO-GAPS.

"LV_LEN = STRLEN( LV_STO ) .

"LV_LEN = LV_LEN - 2.

MOVE LV_STO TO OUT_TAB-VALUE.

MODIFY OUT_TAB INDEX SY-TABIX.

CLEAR LV_LEN.

READ TABLE OUT_TAB WITH KEY 'DISAMO'.

CLEAR OUT_TAB-VALUE.

CONDENSE LV_DAM NO-GAPS.

"LV_LEN = STRLEN( LV_DAM ) .

"LV_LEN = LV_LEN - 2.

MOVE LV_DAM TO OUT_TAB-VALUE.

MODIFY OUT_TAB INDEX SY-TABIX.

READ TABLE OUT_TAB WITH KEY 'LV_GST'.

CLEAR OUT_TAB-VALUE.

CONDENSE LV_GST NO-GAPS.

"LV_LEN = STRLEN( LV_GST ) .

"LV_LEN = LV_LEN - 1.

"MOVE LV_GST(LV_LEN) TO OUT_TAB-VALUE.

MOVE LV_GST TO OUT_TAB-VALUE.

MODIFY OUT_TAB INDEX SY-TABIX.

READ TABLE OUT_TAB WITH KEY 'LV_TOTAL'.

CLEAR OUT_TAB-VALUE.

CONDENSE LV_TOTAL NO-GAPS.

"WRITE : LV_TOTAL no-grouping currency 'SGD'. "ROUND 2 DECIMALS 4.

" LV_LEN = STRLEN( LV_TOTAL ) .

"LV_LEN = LV_LEN - 2.

MOVE LV_TOTAL TO OUT_TAB-VALUE.

"write OUT_TAB-VALUE to OUT_TAB-VALUE decimals 2.

MODIFY OUT_TAB INDEX SY-TABIX.

0 Kudos
669

Hai sai,

Try the table ,

TCURX it contains Decimal Places in Currencies

you can get number of decimals for currency from TCURX table.

then use the FM SPELL_AMOUNT .

Or else you can

goto transaction OY01(oh y zero one) and make the country specific setting.

Regards,

K.Sibi

Edited by: sibi k kanagaraj on Mar 20, 2009 6:59 AM

Former Member
0 Kudos
669

Hi sai,

I get your problem.It needs a detailed explanaiton

you can refer to this wiki

link : [ https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/currencyFormattinginSAPScripts]

It solves your pronlem exactly i guess.If the problem persists , post back.

Regards,

K.SIbi

0 Kudos
669

HI SIBI,

this one s for based on currency wise.....i hav the correct output...but the thing is have to round up decimals

to two places....what ever the ouput came mine s ;like this...

for eg.

total = 665.5461 mine s 665.55.......am getting the first total...next hav to round off...

Former Member
0 Kudos
669

Hi SAI,

Do one thing.

In your subroutine

Declare one variable as

DATA: lv_var TYPE P DECIMALS 2.

Now assign your field to this variable.

i.e lv_var = itab-total.

now in script display this variaable &lv_var&.

regards,

Lokesh

Former Member
0 Kudos
669

Hai ,

Was the problem solved ?

Regards,

K.Sibi

0 Kudos
669

hi sibi,

ya it solved...i declare temporary variable as decimal point...

next i will move to the same orginal variable...it solved...

Former Member
0 Kudos
669

Hi sai,

Happy about it .Even i was thinking abt it but could not figure out the correct solution.

Regards,

K.Sibi

0 Kudos
669

hi sibi,

anyway thanks for the suggestion......