Get MAX value from internal table

Get MAX value from internal table

With SORT


  IF your_table IS NOT INITIAL.
    SORT your_table BY your_field DESCENDING.

    " Get row with max value :
    ls_row_with_max_value = your_table[ 1 ].

    " Get max value :
    lv_max_value = your_table[ 1 ]-your_field.

  ENDIF.

With REDUCE :


" Get row with max value :
DATA(ls_row_max) =  REDUCE ts_row( INIT ls_max = VALUE #( )
                                   FOR ls_row IN lt_table
                                   NEXT ls_max = COND #( 
                                                   WHEN ls_row-count > ls_max-count
                                                   THEN ls_row
                                                   ELSE ls_max ) 
												 ).

About the author

fjourneau administrator

Hi, I'm Florian Journeau, SAP ABAP R3 Freelance, based in Toulouse, France. You want to know more about me, have a look on my CV : cv.fjourneau.net.

Leave a Reply