collect will add up all the numeric fields with the same key, the key is made of all the character fields.
if material batch reason are of type char, and quantity is a numeric field, collect will work.
the reason for not working could be that material is type n and not char or quantity is not a numeric field.
The following will make collect work.
create a table in the following way:
types: begin of y_final_collect,
material(10) type c,
reason(1) type c,
batch(10) type c,
quantity type i, " must be numeric maybe quantity is a type p with 3 decimals
end of y_final_collect.
data gt_final_collect type table of y_final_collect.
data gs_final_collect type y_final_collect.
data gs_final type line of gt_final.
move_corresponding gs_final to gs_final_collect.
loop at gt_final into gs_final,
move_corresponding gs_final to gs_final_collect.
collect gs_final_collect to gt_final_collect.
endloop.