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

simple currency data type calculation doubt

former_member227140
Active Participant
0 Likes
1,381

Hello All,

net_price2 = '12.10'.

DATA : NET_PRICE2 TYPE CHAR20,

NET_PRICE TYPE KBETR,

NET_PRICE1 TYPE CHAR20,

C TYPE CHAR20.

C = 1.

LOOP AT ITAB2.

NET_PRICE = ITAB2-KBETR * C.

C = NET_PRICE.

SHIFT C LEFT DELETING LEADING SPACE.

ENDLOOP.

NET_PRICE1 = C * NET_PRICE2.

in this code i have two values for ITAB2-KBETR .those are 5.00 and 2.00

for first record in loop i am getting value of net_price as (5.00* 1 = 5.00)

but for secodn record what the problem i am facing in i am getting net_price as (5.00*2.00 = 1000.00)......though i want it to

come like 10.

so that net_price1 should come like 12.10 * 10 = 121.....

what i shd do..this type of code now working..please help

Abhijeet

15 REPLIES 15
Read only

Former Member
0 Likes
1,338

Hi,

Try this

DATA : lv_kbetr(20).

LOOP AT ITAB2.

lv_kbetr = ITAB2-KBETR

CONDENse lv_kbetr NO gaps.

NET_PRICE = lv_kbetr * C.

C = NET_PRICE.

SHIFT C LEFT DELETING LEADING SPACE.

ENDLOOP.

Regards

Read only

0 Likes
1,338

hello rasheed,

thnks for the reply first.

but still i am facing same probelm.after going through second record of itab2..it still shows the value of

net_price as 1000.00 (actually what it is doing is net_price = 5.00 * 2.00 = 1000.00)......

any other idea.??

Read only

0 Likes
1,338

copy the result into a character type before displaying. or take both variables in char variables and then multiply.

Regards,

Sumit Nene

Read only

0 Likes
1,338

hi sumit...

even i tried in that way also...i am not getting desired results...

Read only

Former Member
0 Likes
1,338

Hi ,

Use follwoing code..

Declare all varibel as type of KBETR (no need of char)


DATA : NET_PRICE2 TYPE kbetr value '12.10',
NET_PRICE TYPE KBETR,
NET_PRICE1 TYPE KBETR,
C TYPE KBETR.

C = 1.
LOOP AT ITAB2.
NET_PRICE = ITAB2-KBETR * C.
C = NET_PRICE.
*SHIFT C LEFT DELETING LEADING SPACE. " del
ENDLOOP.
NET_PRICE1 = C * NET_PRICE2.
WRITE:/ NET_PRICE1.

Hope this solves your issue,

Nag

Read only

0 Likes
1,338

hello nag,

even i tried this ..but the problem is during second record....

net_price = 5.00 * 2.00 = 1000.00

its doing.......so there lies the problem.

Read only

0 Likes
1,338

Hi Abhijeet,

Please check the type of ITAB2-KBTER (is it also type kbter)

i have tried folloing code -- result is 121


REPORT  ZTEST_133294.
DATA : NET_PRICE2 TYPE kbetr value '12.10',
NET_PRICE TYPE KBETR,
NET_PRICE1 TYPE KBETR,
C TYPE KBETR.
DATA: BEGIN OF ITAB2 OCCURS 0,
         KBETR TYPE KBETR,
      END OF ITAB2.
      ITAB2-KBETR = '5.00'.
      APPEND ITAB2.
      ITAB2-KBETR = '2.00'.
      APPEND ITAB2.
C = 1.
LOOP AT ITAB2.
NET_PRICE = ITAB2-KBETR * C.
C = NET_PRICE.
*SHIFT C LEFT DELETING LEADING SPACE.
ENDLOOP.
NET_PRICE1 = C * NET_PRICE2.
WRITE:/ NET_PRICE1.

Hope this helps,

Nag

Edited by: Naga Mohan Kummara on Jan 6, 2010 6:56 AM

Read only

0 Likes
1,338

hello nag,

thnkas for the answer.

same code i have executed in se38 so its value is coming 121.

but actually i am writting this code in VOFM routine.......in Formulas...

where this code is making calculations as net_price = 5.00 * 2.00 = 1000.00...

so can u suggest any other thing...

Read only

0 Likes
1,338

Hi,

Create a temp varible type (kbetr / F) and move ITAB2-KBETR before calculation and carry out calculations...

Nag

Read only

Former Member
0 Likes
1,338

Hi

Try this

data: begin of itab occurs 0,

kbetr type kbetr,

end of itab.

DATA : NET_PRICE2 TYPE CHAR20,

NET_PRICE TYPE KBETR,

NET_PRICE1 TYPE CHAR20,

C TYPE i.

start-of-selection.

itab-kbetr = 5.

append itab.

itab-kbetr = 2.

append itab.

C = 1.

LOOP AT ITAB.

NET_PRICE = ITAB-KBETR * C.

C = NET_PRICE.

*SHIFT C LEFT DELETING LEADING SPACE.

ENDLOOP.

NET_PRICE1 = C * NET_PRICE.

Read only

0 Likes
1,338

I suppose this problem may be due to "Fixed Point Arithmetic" property.

It is set in the program, hence it is working.

We need to check whether we can set this in VOFM formula.

Regards,

Raveesh

Edited by: raveesh saurabh on Jan 6, 2010 9:33 AM

Read only

0 Likes
1,338

I guess Rajashekhar's trick should work.

He has declared C as an INTEGER.

Only thing is ITAB-KBETR should not have any decimal points.

For the example given by you, it should work.

I don't have the system currently hence can not check.

Let us know whether it worked or not.

Also I think it is because of "Fixed Point Arithmetic" attribute.

It is not set in your main program. And you VOFM formula has been included as an INCLUDE, and hence this include takes this attribute from the main program.

Regards,

Raveesh

Read only

0 Likes
1,338

Hello All,

i have done like this........its working.....but do let me know your commnets ....

CHECK PREISFINDUNGSART EQ 'B'.

TYPES : BEGIN OF T_KONP ,

KBETR TYPE KONP-KBETR,

MATNR TYPE A073-MATNR,

KNUMH TYPE A073-KNUMH,

END OF T_KONP.

TYPES : BEGIN OF T_A004,

KNUMH TYPE A004-KNUMH,

KBETR TYPE KONP-KBETR,

KSCHL TYPE A004-KSCHL,

END OF T_A004.

DATA : ITAB TYPE STANDARD TABLE OF T_KONP WITH HEADER LINE,

ITAB1 TYPE STANDARD TABLE OF T_A004 WITH HEADER LINE,

ITAB2 TYPE STANDARD TABLE OF T_A004 WITH HEADER LINE.

DATA : NET_PRICE2 TYPE kbetr value '12.10',

NET_PRICE TYPE P DECIMALS 6,

NET_PRICE1 TYPE KWERT,

C TYPE P DECIMALS 4.

NET_PRICE2 = '12.10'.

SELECT KNUMH INTO CORRESPONDING FIELDS OF TABLE ITAB1 FROM A004 WHERE

MATNR = KOMP-MATNR.

IF SY-SUBRC = '0'.

SELECT KBETR KSCHL KNUMH INTO CORRESPONDING FIELDS OF TABLE ITAB2 FROM KONP FOR ALL

ENTRIES IN ITAB1 WHERE KNUMH = ITAB1-KNUMH.

ENDIF.

C = 1.

LOOP AT ITAB2.

NET_PRICE = ITAB2-KBETR * C.

C = NET_PRICE.

ENDLOOP.

NET_PRICE1 = ( C * NET_PRICE2 ) / 10000 .

XKWERT = NET_PRICE1.

Read only

0 Likes
1,338

by the code i posted.....like i have done......(previous post was total code)..but solved the problem by,

DATA : NET_PRICE2 TYPE kbetr value '12.10',

NET_PRICE TYPE P DECIMALS 6,

NET_PRICE1 TYPE KWERT,

C TYPE P DECIMALS 4.

C = 1.

LOOP AT ITAB2.

NET_PRICE = ITAB2-KBETR * C.

C = NET_PRICE.

ENDLOOP.

NET_PRICE1 = ( C * NET_PRICE2 ) / 10000 .

XKWERT = NET_PRICE1.

let me know u r comments

Read only

former_member227140
Active Participant
0 Likes
1,338

ok