Hi,
I suggest to analyze in detail where the performance bottlenecks are. You can do that using debugging. Did you do that? Which statement(s) is/are consuming a lot of time?
I suspect that the SELECT ... FOR ALL ENTRIES could be a potential performance killer. You always have to be very careful with it and only use a list of distinct values as input. Firstly you should e.g. copy the RESULT_PACKAGE, sort it on Billing Document and Document Item and then DELETE ADJACENT DUPLICATES. This will lead to a list of distinct values.
Furthermore, I suggest to leave out the Quantity for the selection. It might be better to work with a bigger table and do the logic afterwards with the READ statement.
Last but not least (as suggested by others), do everything within a single LOOP ... ENDLOOP.
Best regards,
Sander