If Excel Row matches append document number with comma

welcome to the forum

it can be handled with grouping the data on SAP FP Code and processing the resulting group members.

Have a further look here:

refering to you screenshots also duplicated rows are to remove on advance