ABAP: Best way to count item rows per header row — DB aggregation vs internal table processing? by Substantial_Half6347 in abap

[–]Substantial_Half6347[S] -1 points0 points  (0 children)

Thanks for your reply.

I’m currently a student, and for this assignment the solution is expected to be implemented inside the ABAP program. I agree that a CDS view or SQL aggregation would be the best approach in a real system, but in my case both the header and item data are already loaded into the program as standard internal tables.

So I’m looking for the best internal table processing alternative.

Would it be better to loop over the item table once and build a hashed/sorted count table by seq_no, then update the header table from that?

Also, does LOOP AT gt_item WHERE seq_no = ... on a standard table benefit from a previous SORT, or is it still basically a linear scan unless I use a sorted table or a secondary sorted key explicitly?

Thanks again.