Determine max / min value of internal table column with REDUCE

Tags: ABAP

It comes handy, when you need to allocate the next item number of a document. The task is always to get the highest number first. 

DATA:
  po_items	TYPE STANDARD TABLE of ekpo.
	  
DATA(max_num) = REDUCE numc5( INIT res = '00000'  FOR line IN po_items
	NEXT res = COND #( WHEN line-ebelp > res THEN line-ebelp ELSE res ) 
).

You can also get the lowest number, the complexity of comparison is up top You to do something different with a particular column. Here the focus is on the new REDUCE statement.

Applicable in NW 7.5 and onwards.