‎2006 Nov 14 3:29 PM
Hi Friends,
I need to use MIN to get the minimum of 3 values . I have 3 internal tables with material and price in each interenal table . How can i get the minimum price from these 3 internal tables .
SELECT matnr net_price
INTO TABLE ltab1
FROM ztable1
WHERE matnr = z_matnr
SELECT matnr net_price
INTO TABLE ltab2
FROM Ytable2
WHERE matnr = z_matnr
SELECT matnr net_price
INTO TABLE ltab3
FROM xtable3
WHERE matnr = z_matnr
Loop at t_out
Read table itab1 BINARY SEARCH WITH KEY matnr = t_out-matnr.
Read table itab2 BINARY SEARCH WITH KEY matnr = t_out-matnr.
Read table itab3 BINARY SEARCH WITH KEY matnr = t_out-matnr.
.....
[....How do i get lowest price from these 3 tables ? ]
...
endloop
Thanks ,
Message was edited by:
Hari G Krishna
‎2006 Nov 14 3:41 PM
Hi,
Move all then data into another internal table (itab4) then sort itab4 by matnr price ascending.
read table itab4 index 1.
Which will give u the lower price .
Cheers.
‎2006 Nov 14 3:39 PM
Hi Hari,
sort the 3 itabs by net_price and take the first record.
Regards, Dieter
‎2006 Nov 14 3:39 PM
Sort each table by price then read the first record from each table. Then compare these values to get the minimum of all the tables.
Rob
‎2006 Nov 14 3:41 PM
Hi,
Move all then data into another internal table (itab4) then sort itab4 by matnr price ascending.
read table itab4 index 1.
Which will give u the lower price .
Cheers.
‎2006 Nov 14 3:50 PM
Another solution would be to add the values of each to another internal table and then sort that internal table and read the first line.
data: begin of tmp_tab occurs 0,
matnr type mara-matnr,
stprs type mbew-stprs,
end of tmp_tabl.
Loop at t_out
clear tmp_tab. Refresh tmp_tab.
Read table itab1 BINARY SEARCH WITH KEY matnr = t_out-matnr.
move-corresponding itab1 to tmp_tab.
append tmp_tab.
Read table itab2 BINARY SEARCH WITH KEY matnr = t_out-matnr.
move-corresponding itab2 to tmp_tab.
append tmp_tab.
Read table itab3 BINARY SEARCH WITH KEY matnr = t_out-matnr.
move-corresponding itab3 to tmp_tab.
append tmp_tab.
.....
[....How do i get lowest price from these 3 tables ? ]
...
sort tmp_tab ascending by stprs.
read table tmp_tab index 1.
write:/ tmp_tab-stprs, 'is the lowest of the three'.
endloop
Regards,
RIch Heilman
‎2006 Nov 14 3:53 PM
Thank you Rich and everyone out there.That was very helpful.
Message was edited by:
Hari G Krishna