‎2009 Jun 02 8:24 AM
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
‎2009 Jun 02 8:28 AM
Hi neetu,
use unit as
data : unit type mbew-lbkum.
regards,
ravibabu.a
‎2009 Jun 02 8:29 AM
‎2009 Jun 02 8:31 AM
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.
‎2009 Jun 02 8:32 AM
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
‎2009 Jun 02 8:38 AM
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.