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

round function problem

Former Member
0 Likes
2,862

hi experts,

in my requirement i have a problem that in quantity fields i am getting the wrong value after 4 decimals

pls go through the followin ex.

suppose my calculated value is 2039.417140256, but the value i am getting is 2039.417, the actual value i have to get is 2039.418

similarly for 2148.19556709,i am getting 2148.196 which is equal to actual value i have to get

similarly for 218.56573508, i am getting 218.566 which is equal to actual value i have to get

from the above ex i have to ceil the fourth decimal of my total no ,

i have tried ceil ,but my total no is getting rounded to next higher no

which will result in large variation with my actual value.

can any body pls suggest me how to ceil the fourth decimal of my no with some sample code

thanks&regards

maheshlap

27 REPLIES 27
Read only

surajarafath
Contributor
0 Likes
2,720

I think it is working correct.. if you round off 2039.417140256 this value you should get 2039.417. This is the Correct round off right?

can i know why you want as 2039.418?? and the 4th Decimal point?

Read only

0 Likes
2,720

hi suji,

my requirement is same as t-code cs11, it is a report which will show all the materials prior to selection ( unlike cs11 which shows single material ) and its components and its quantities including scrap.

here the valu i am getting is ex.2039.417

in cs11 the same value is 2039.418, i have checked my value which is differ in the fourth decimal thats y i need to ceil

the fourth decimal place,

that minute variation also leads to large varition in weight thats y i need.

sorry i havent used any round function here, i just want to ceil fourth decimal place.

i hope u got it now.

thanks.

Read only

0 Likes
2,720
data: p1 type p DECIMALS 3.
data: f1 type f.
f1 =  '2039.417140256'.
f1 = f1 * 1000.
f1 = ceil( f1 ).
f1 = f1 / 1000 .
move f1 to p1. WRITE p1.
Read only

0 Likes
2,720

hi soumya ,

still i am getting the same value, can u plz suggest me another way.

the calculated value i am getting is 1751.007

but the actula val in cs11 is 1750.971

ex. v_tamnt = 30000,v_bmeng = 350.010,w_halb-mngko = 55.300


IF W_HALB-MTART = 'ROH' OR W_HALB-MTART = 'PERS'.
          W_HALB-WOSQTY = ( ( V_TAMNT * W_HALB-MNGKO ) / V_BMENG ).
          F1 = W_HALB-WOSQTY.
          F1 = F1 * 1000.
          F1 = CEIL( F1 ).
          F1 = F1 / 1000.
          MOVE F1 TO W_HALB-WOSQTY.
          CLEAR F1.
          W_HALB-SQTY =  ( ( W_HALB-MNGKO * W_HALB-AVOAU ) / 100 ).
          W_HALB-SQTY = ( ( V_TAMNT * W_HALB-SQTY ) / V_BMENG ).
          F1 = W_HALB-SQTY.
          F1 = F1 * 1000.
          F1 = CEIL( F1 ).
          F1 = F1 / 1000.
          MOVE F1 TO W_HALB-SQTY.
          CLEAR F1.
          W_HALB-TOQTY = W_HALB-WOSQTY + W_HALB-SQTY.
        ELSE.
          IF W_HALB-MTART = 'HALB'.
            W_HALB-WOSQTY = (  ( V_TAMNT * W_HALB-MNGKO ) / V_BMENG ) .
            F1 = W_HALB-WOSQTY.
            F1 = F1 * 1000.
            F1 = CEIL( F1 ).
            F1 = F1 / 1000.
            MOVE F1 TO W_HALB-WOSQTY.
            CLEAR F1.
            W_HALB-SQTY =  ( ( W_HALB-MNGKO * W_HALB-AVOAU ) / 100 ).
            W_HALB-SQTY = ( ( V_TAMNT * W_HALB-SQTY ) / V_BMENG ).
            F1 = W_HALB-SQTY.
            F1 = F1 * 1000.
            F1 = CEIL( F1 ).
            F1 = F1 / 1000.
            MOVE F1 TO W_HALB-SQTY.
            CLEAR F1.
            W_HALB-TOQTY = W_HALB-WOSQTY + W_HALB-SQTY.

can any body pls suggets me

thanks.

Read only

0 Likes
2,720

Hi friend,

Try to increase the decimal value by one and then move it again to the decimal which you required.

Just try like the below code,

data: p1 type p DECIMALS 4.

data: f1 type p DECIMALS 3.

p1 = '2039.417140256'.

p1 = p1 * 1000.

p1 = ceil( p1 ).

p1 = p1 / 1000 .

move p1 to f1.

WRITE p1.

WRITE f1.

I think this solves you problem else please revert back to me i will help you.

Thanks,

Sri Hari

Read only

0 Likes
2,720

hi frnd,

still there is no change , i am getting the same val as above mentioned.

help pls.

thanks.

Read only

0 Likes
2,720

Hi friend,

For the code below which you have mentioned as your sample code

i am getting the value 4.739,8650.

Is this the answer which you needed??.

Please revert back me for queries......

DATA : v_bmeng TYPE p DECIMALS 4.

DATA : w_halb-mngko TYPE p DECIMALS 4.

DATA : v_tamnt TYPE i.

DATA : w_halb-wosqty TYPE p DECIMALS 4,

w_halb-toqty TYPE p DECIMALS 4,

w_halb-sqty TYPE p DECIMALS 4,

w_halb-avoau TYPE p DECIMALS 4,

f1 TYPE p DECIMALS 4,

w_halb-mtart(4) TYPE c.

v_tamnt = '30000'.

v_bmeng = '350.010'.

w_halb-mngko = '55.300'.

w_halb-mtart = 'HALB'.

IF w_halb-mtart = 'ROH' OR w_halb-mtart = 'PERS'.

w_halb-wosqty = ( ( v_tamnt * w_halb-mngko ) / v_bmeng ).

f1 = w_halb-wosqty.

f1 = f1 * 1000.

f1 = CEIL( f1 ).

f1 = f1 / 1000.

MOVE f1 TO w_halb-wosqty.

CLEAR f1.

w_halb-sqty = ( ( w_halb-mngko * w_halb-avoau ) / 100 ).

w_halb-sqty = ( ( v_tamnt * w_halb-sqty ) / v_bmeng ).

f1 = w_halb-sqty.

f1 = f1 * 1000.

f1 = CEIL( f1 ).

f1 = f1 / 1000.

MOVE f1 TO w_halb-sqty.

CLEAR f1.

w_halb-toqty = w_halb-wosqty + w_halb-sqty.

ELSEIF w_halb-mtart = 'HALB'.

w_halb-wosqty = ( ( v_tamnt * w_halb-mngko ) / v_bmeng ) .

f1 = w_halb-wosqty.

f1 = f1 * 1000.

f1 = CEIL( f1 ).

f1 = f1 / 1000.

MOVE f1 TO w_halb-wosqty.

CLEAR f1.

w_halb-sqty = ( ( w_halb-mngko * w_halb-avoau ) / 100 ).

w_halb-sqty = ( ( v_tamnt * w_halb-sqty ) / v_bmeng ).

f1 = w_halb-sqty.

f1 = f1 * 1000.

f1 = CEIL( f1 ).

f1 = f1 / 1000.

MOVE f1 TO w_halb-sqty.

CLEAR f1.

w_halb-toqty = w_halb-wosqty + w_halb-sqty.

ENDIF.

WRITE : w_halb-toqty.

Thanks,

Sri Hari

Read only

0 Likes
2,720

>hi soumya ,

> still i am getting the same value, can u plz suggest me another way.

> the calculated value i am getting is 1751.007

> but the actula val in cs11 is 1750.971

> ex. v_tamnt = 30000,v_bmeng = 350.010,w_halb-mngko = 55.300

> thanks.

can you quickly tell me what the calculation here... and what the input and whats the ouput required(for this exact example)

Read only

0 Likes
2,720

hi srihari,

i want to ceil fourt decimal place after the point

i tried above total decimal point got affected.

can u check once

thanks..

Read only

0 Likes
2,720

hi soumya,

output is 1751.001

actual op val in cs11 is 1750.971

cal code i have provided above.

thanks

Read only

0 Likes
2,720

Did you try what i said ? Please check it.

Kesav

Read only

0 Likes
2,720

W_HALB-WOSQTY - whats the type for this!!

Read only

0 Likes
2,720

Was that to me

Read only

0 Likes
2,720

hi keshav,

i am trying but i am not able to understand that,

could u pls help me.

Read only

0 Likes
2,720

Was that to me

😛 yes, actually i was about to write Kesav has suggested a really nice piece of code, then i got diverted towards the actual post i did

@Mahesh.

W_HALB-WOSQTY - whats the type for this!!

Read only

0 Likes
2,720

hi soumya,

w_halb-wosqty type kmpmg.

Read only

0 Likes
2,720

hi keshav,

i am trying but i am not able to understand that,

could u pls help me.

Please debug that code from CS11 and understand it. It will be helpful more than I explain it.

Kesav

Read only

0 Likes
2,720

one last question... what is the type and value of W_HALB-AVOAU ?

i am trying to replicate your code

Read only

0 Likes
2,720

ha keshav,

i am trying debugging cs11 i didnt found that include or piece of code comming may i?

i will check out that

is ther any other way with piece of code.

thanks.

Read only

0 Likes
2,720

Hi friend,

You have said,

the calculated value i am getting is 1751.007

but the actula val in cs11 is 1750.971

I am asking whether are you getting this value for your mentioned code with that values???

Thanks,

Sri Hari

Read only

0 Likes
2,720

hi soumya,

avoau type avoau, scrap percentage.

it will present in struct stpox.

Read only

0 Likes
2,720

whats the value of it in your code?

Read only

0 Likes
2,720

hi soumya,

i am giving the set of vals

v_tamnt = 30000

v_bmeng = 350.010

w_halb-mngko = 2.700

w_halb-avoau = 0.025%

now the val i am gettin after calc is 232.022

but with the same values

in cs11 the actual val after calc is 232.001

with the above code i have used

where i am gettin wrong

pls help

thanks

Read only

0 Likes
2,720

Now check it with sample code


   PERFORM T006_LESEN USING DEC_MEINS. "DEC_MEINS is the unit of measure
   L_DECIMALS = T006-ANDEC.   "No. of decimal places to which rounding should be performed from table T006
   IF L_DECIMALS IS INITIAL.
      L_DECIMALS = T006-DECAN.
   ENDIF.

*--Calculation part
   DO L_DECIMALS TIMES.
      P1 = P1 * 10.                 "Initially P1 holds 1
   ENDDO.
 
*- Konvertierung in Float
   M = DEC_MENGE.         "Quantity
   X1 = P1 * M / 1000.
   X2 = CEIL( X1 ).

Read only

0 Likes
2,720

@Kesav;

haha, if mahesh comes back without trying this, i guess you are gonna reach there and open this code and show it to him

Read only

0 Likes
2,720

Soumya,

That was too funny :P...The logic is there and its really disturbing when its not tried and waiting for sample codes ( feeding ).

$%#%$#%$ stopped watching this thread.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,720

Goto Include LCSDIF53 , subroutine DECIMALS_CHECK and check what is happening. Debug CS11 placing a break-point here.

Copied from routine .


CHECK ( NOT DEC_MEINS IS INITIAL ) AND
         ( NOT DEC_MENGE IS INITIAL ).

   DATA: M  TYPE F,
         P1 TYPE F VALUE 1,
         X1 TYPE F,
         X2 TYPE F,
         L_DECIMALS LIKE T006-DECAN,
         l_msgty    like sy-msgty.                       "note 517410

   PERFORM T006_LESEN USING DEC_MEINS.
   L_DECIMALS = T006-ANDEC.
   IF L_DECIMALS IS INITIAL.
      L_DECIMALS = T006-DECAN.
   ENDIF.
   DO L_DECIMALS TIMES.
      P1 = P1 * 10.
   ENDDO.

*- Konvertierung in Float
   M = DEC_MENGE.
   X1 = P1 * M / 1000.
   X2 = CEIL( X1 ).