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

read statement

Former Member
0 Likes
612

hi,

i need to calculate unit value.

can i calculate as below in loop statement.

data : unit type i.

loop at gt_mard.

READ TABLE gt_mbew WITH KEY matnr = gt_mard-matnr BINARY SEARCH.

IF sy-subrc = 0.

move gt_mbew-salk3 to gt_data-salk3.

move gt_mbew-lbkum to gt_data-lbkum.

move gt_mbew-bklas to gt_data-bklas.

Unit = gt_mbew-salk3 / gt_mbew-lbkum.

move unit to gt_data-unitcost.

ENDIF.

endloop.

please let me know it is correct or not.

thanks in advance

5 REPLIES 5
Read only

Former Member
0 Likes
564

Hi neetu,

use unit as

data : unit type mbew-lbkum.

regards,

ravibabu.a

Read only

Former Member
0 Likes
564

Hello

Yes, correct.

But do not forget sort gt_mbew by matnr.

Read only

Former Member
0 Likes
564

data : unit type i.

SORT gt_mbew BY MATNR.

loop at gt_mard.

READ TABLE gt_mbew WITH KEY matnr = gt_mard-matnr BINARY SEARCH.

IF sy-subrc = 0.

move gt_mbew-salk3 to gt_data-salk3.

move gt_mbew-lbkum to gt_data-lbkum.

move gt_mbew-bklas to gt_data-bklas.

Unit = gt_mbew-salk3 / gt_mbew-lbkum.

move unit to gt_data-unitcost.

APPEND GT_DATA TO GT_DATA[].

CLEAR GT_DATA ,GT_MBEW.

ENDIF.

endloop.

Read only

Former Member
0 Likes
564

Hi Neethu,

You can directly do the calculations to the field gt_data-unitcost by

gt_data-unitcost = gt_mbew-salk3 / gt_mbew-lbkum.

before that u need to check the field gt_mbew-lbkum should not be 0, otherwise the above statement will go into dump if it is zero, as dividing an integer with 0 gives to infinity.

thanks,

Rakesh

Read only

Former Member
0 Likes
564

Hi Neetu,

your code is correct. But When ever you go in for Binary search , you need to sort the internal table with the key (in your case - matnr ) in which you are using to read it.

data : unit type i.

sort gt_mbew ascending by matnr.

loop at gt_mard.

READ TABLE gt_mbew WITH KEY matnr = gt_mard-matnr BINARY SEARCH.

IF sy-subrc = 0.

move gt_mbew-salk3 to gt_data-salk3.
move gt_mbew-lbkum to gt_data-lbkum.
move gt_mbew-bklas to gt_data-bklas.

Unit = gt_mbew-salk3 / gt_mbew-lbkum.

move unit to gt_data-unitcost.

ENDIF.
endloop.

plz check this line too for your reference.

[http://help.sap.com/abapdocu/en/ABAPREAD_TABLE_FREE.htm#!ABAP_ONE_ADD@1@]

Regards,

Sakthi.