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

MIN function

Former Member
0 Likes
831

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
730

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.

5 REPLIES 5
Read only

Former Member
0 Likes
730

Hi Hari,

sort the 3 itabs by net_price and take the first record.

Regards, Dieter

Read only

Former Member
0 Likes
730

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

Read only

Former Member
0 Likes
731

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.

Read only

0 Likes
730

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

Read only

0 Likes
730

Thank you Rich and everyone out there.That was very helpful.

Message was edited by:

Hari G Krishna