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

value conversion

Former Member
0 Likes
798

i have a problem with net price conversion

<b>v_per = ( v_bpumz1 / v_bpumn1 ) * ( v_netpr1 / v_peinh1 ).</b>

the value v_netpr1 is getting 1000 instead of 10,00 so the caluculation is getting wrong, its printing up 500 instead of 5.

data: v_netpr(80) type c,

v_peinh(80) type c,

*Begin of changes by GGUPTA.

v_bpumz(80) type c,

v_bpumn(80) type c,

*End of changes by GGUPTA.

v_netpr1(13) type p decimals 2,

v_peinh1(13) type n,

*Begin of changes by GGUPTA.

v_bpumz1(13) type n,

v_bpumn1(13) type n,

*End of changes GGUPTA.

v_per(13) type p decimals 2.

constants: c_usd(3) type c value 'USD'.

CLEAR: v_netpr, v_peinh,v_per.

  • Net Price

READ TABLE in_par INDEX 1.

IF sy-subrc = 0.

v_netpr = in_par-value.

*remove the commas

REPLACE ALL OCCURRENCES OF ',' IN v_netpr WITH ''.

ENDIF.

  • Per

READ TABLE in_par INDEX 2.

IF sy-subrc = 0.

v_peinh = in_par-value.

ENDIF.

*Begin of changes by GGUPTA.

READ TABLE in_par INDEX 3.

IF sy-subrc = 0.

v_bpumz = in_par-value.

ENDIF.

READ TABLE in_par INDEX 4.

IF sy-subrc = 0.

v_bpumn = in_par-value.

ENDIF.

*End of changes by GGUPTA.

condense: v_netpr, v_peinh,

*Begin of changes by GGUPTA.

v_bpumz, v_bpumn.

*End of changes by GGUPTA.

write v_netpr to v_netpr1.

write v_peinh to v_peinh1.

*Begin of changes by GGUPTA.

write v_bpumz to v_bpumz1.

write v_bpumn to v_bpumn1.

*End of changes by GGUPTA.

*Begin of changes by GGUPTA.

  • v_per = v_netpr1 / v_peinh1.

v_per = ( v_bpumz1 / v_bpumn1 ) * ( v_netpr1 / v_peinh1 ).

*End of changes by GGUPTA.

  • Sending Per info back

READ TABLE out_par INDEX 1.

IF sy-subrc = 0.

*Begin of changes by GGUPTA.

  • WRITE v_PER currency c_usd left-justified TO out_par-value.

WRITE v_PER currency c_usd left-justified TO out_par-value.

*End of changes by GGUPTA.

MODIFY out_par INDEX 1.

ENDIF.

<b></b>

6 REPLIES 6
Read only

Former Member
0 Likes
748

check out if <b>Fixed Point Arithmetic</b> check box is checked in the program attributes

goto Se38--Program name -->display

in the menu>attributes>Fixed Point Arithmetic checkbox

If you mark this checkbox, all caluculations in the program will use fixed point arithmetic.

If you do not, packed numbers (ABAP/4 type P, Dictionary types CURR, DEC or QUAN) will be treated as integers when they are used in assignments, comparisons and calculations, irrespective of the number of decimal places defined. Intermediate results in arithmetic calculations will also be rounded to the next whole number. The number of decimal places defined is only taken into account when you output the answer using the WRITE statement.

Message was edited by:

Chandrasekhar Jagarlamudi

Read only

Former Member
0 Likes
748

Hi

Check the line

REPLACE ALL OCCURRENCES OF ',' IN v_netpr WITH ''.

Here 10,00(Ten) gets converted to 10 00 and after condensing it, the value becomes 1000(Thousand) and not 10(Ten).

So when you are moving the value to v_netpr1, you are sending one thousand and not ten.

Regards

Navneet

Read only

0 Likes
748

hi naveent know i am getting proper output as 5,00 but i need output as 5.00 can u help me out in this.

Read only

0 Likes
748

Hi

Goto

system->user profile->own data-> dafault.

There you choose the decimal notation.

Regards

Navneet

Read only

0 Likes
748

i am getting properly in abap debugging as 5.00,when its moving to sap script while displaying its converting to 5,00

Read only

Former Member
0 Likes
748

Dear Chaya,

In the data declaration area, please don't use direct types like N, C instead declare like this:

DATA: V_NETPR LIKE EKPO-NETPR.

For all the variables do it this way.

Remember this:

For a particular field always goto SE11 --> Enter Table Name : EKPO --->

Search the field for e.g. NETPR ---> Goto the data element : BPREI

-


> Goto the Domain : WERT11 --> Double Click on it ---> You'll see the Output Length is 14.

Thats why its always recommended to keep it the same as used by SAP.

Regards,

Abir

************************************

  • Don't forget to award Points *