Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Regarding Max/Min from an internal table

Hello Experts !

I have been through various threads in the ABAP forum, however, couldn't find any solution for my query.

I need to find the maximum and minimum values from an internal table.

e.g.

Particulars Col1 Col2 Col3 Col4 Col5

A 4 8 2 9 7

B 1 5 6 3 4

C 8 2 3 4 7

-


Min 1 2 2 3 4

-


Max 8 8 6 9 7

-


Can anyone give me a few suggestions on this. How do I need to proceed?

Thanks,

Aasim

replied

>

> Hello Experts !

>

> I have been through various threads in the ABAP forum, however, couldn't find any solution for my query.

> I need to find the maximum and minimum values from an internal table.

>

> e.g.

>

> Particulars Col1 Col2 Col3 Col4 Col5

> A 4 8 2 9 7

> B 1 5 6 3 4

> C 8 2 3 4 7

> -


> Min 1 2 2 3 4

> -


> Max 8 8 6 9 7

> -


>

>

> Can anyone give me a few suggestions on this. How do I need to proceed?

>

> Thanks,

> Aasim

below pseudo code should work

data : wa_max type workarea ,
         wa_min  type workarea ,
         wa_tmp type workarea .

loop at internal_table into wa_tmp.
 if sy-tabix = 1 ,
   wa_max = wa_tmp.
   wa_min = wa_tmp.
 else.
*    minimum
      if wa_tmp-Col1 < wa_min-Col1 .
          wa_min-Col1 = wa_tmp-Col1 .
      endif.   
*     repeat above IF.ENDIF for each col

*    Maximum
      if wa_tmp-Col1 > wa_max-Col1 .
          wa_max-Col1 = wa_tmp-Col1 .
      endif.   
*     repeat above IF.ENDIF for each col


 endif.
endloop.

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question