Assume itab1 holds the basic data and you have one work are of same type (wa1). Now create another internal table of same type ( itab2) and work area also ( wa2).
LOOP AT itab1 INTO wa1.
LOOP AT itab2 INTO wa2 WHERE material_no = wa1-material_no.
wa2-quantity = wa2-quantity + wa1-quantity.
MODIFY itab2 FROM wa2.
ENDLOOP.
IF sy-subrc NE 0.
APPEND wa1 TO itab2.
ENDIF.
ENDLOOP.
Now check itab2 for your required o/p.