The logic is not complete. If the max value is the first one, it will not be saved to maxval. This would be the proper solution:
loop at itab into wa1.
maxval = wa1-cumquantity.
read table itab into wa2 index sy-index + 1.
if wa2-CUMQUANTITY > wa1-CUMQUANTITY.
maxval = wa2-CUMQUANTITY.
endif.
endloop.