Application Development 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: 

HOW TO MANIPULATE WITH TABLES BASED ON UNIT..?

Former Member
0 Kudos

Hi,

Itab1

material      Qty      unit

------------------------------

1MP0014      10      kg.

1MP0012      20      m.

1MP0017      20      ea.

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

Itab2.

material      Qty      unit

---------------------------------

1MP0014      10      ea.

1MP0012      60      mm.

1MP0017      30      m.

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

Material 1MP0014.

Bae unit for this material is KG.

Alternative unit for this material is ea,mm,m etc.

I want to sum or subtract above two internal tables based upon unit.

I mean if units are equal then no problem.

if units are not equal then i want to convert all itab2 materials unit of measure into itab1 unit of measure.

please guide me how can I convert unit of measure.

5 REPLIES 5

VijayaKrishnaG
Active Contributor
0 Kudos

Hi Sri Devi,

I was a bit confused with your query.


if units are not equal then i want to convert all itab2 materials unit of measure into itab1 unit of measure.

As of my understanding, if we consider a material let's say 1MP0014. This material exists in two internal tables. Now as the base unit is KG, now the UOM 'EA' has to be converted into KG and the Sum of two quantities (10 KG + 10 ea/KG ) has to calculate.

Am I right???

If my understanding was wrong, please ignore and hope you can explain a bit clear.

Thanks and Regards,

Vijay

0 Kudos

NO,sir.

If units are not equal then i want to convert itab2 materials units into

itab1 material units.

Material 1MP0014 in itab1 its unit is kg and in itab2 its unit is ea.

Actually,Base unit of this material is kg.

And alternative units are ea,mm,m,etc.

For example, I can define alternative unit for this material as follows.

1 kg = 10 ea.

SO in itab2

1mp0014 10 ea.

In this case I want to convert like this

Sum of this material is 10 kg(from itab1) + 1 kg(from itab2)  = 11 kg.

i.e  1 kg = 10 ea.

In this way i want to caluclate.please guide me.

0 Kudos

Hi,

If same material exists multiple times in table-2, the Loop the Table-2 using parallel processor then convert the Units and calculate the sum. It would be better if you collect into another internal table.

If a material exists only once, then use Read statement instead of loop and do the same conversion and calculation.

For conversion of units you can use function modules.

You should not manipulate the table basing on Units.

If further clarifications need, please revert.

Regards,

Vijay

Former Member
0 Kudos

Hi Sri Devi,

Loop Itab1 internal table and read itab2 table with material as key then use function module MATERIAL_UNIT_CONVERSION to convert quantity based unit of measure, modify itab2 with converted quantity. Search in SCN to know more about MATERIAL_UNIT_CONVERSION

Thanks & Regards,

Arun

Former Member
0 Kudos

Hi,

You can use  UNIT_CONVERSION_SIMPLE fm for the same.

Example was there in SCN itself.

DATA : p_input TYPE p DECIMALS 3.

DATA: p_output TYPE p DECIMALS 3.

p_input = '100.000'.

CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'

EXPORTING

input = p_input

no_type_check = 'X'

round_sign = '+'

unit_in = 'KG'

unit_out = 'LB'

IMPORTING

output = p_output.

WRITE: sy-subrc,':'.

WRITE p_output.


Loop it_tab1.

    Read it_tab2.

     Check if material is equal and unit is not equal.

       Use the FM and Add Quantities.

    Check if material is equal and unit is equal.

      Add Quantities.

Endloop.


Regards.