Interview Questions

What is the Difference Between Collect and Sum?

SAP Reports,SAP DB,ALE, SAP Tables questions and answers


(Continued from previous question...)

What is the Difference Between Collect and Sum?

COLLECT allows you to create unique or summarized datasets. The system first tries to find a table entry corresponding to the table key. The key values are taken either from the header line of the internal table itab, or from the explicitly-specified work area.
If the system finds an entry, the numeric fields that are not part of the table key (see ABAP number types) are added to the sum total of the existing entries. If it does not find an entry, the system creates a new entry instead.
The way in which the system finds the entries depends on the type of the internal table:

- STANDARD TABLE:
The system creates a temporary hash administration for the table to find the entries. This means that the runtime required to find them does not depend on the number of table entries. The administration is temporary, since it is invalidated by operations like DELETE, INSERT, MODIFY, SORT, ...). A subsequent COLLECT is then no longer independent of the table size, because the system has to use a linear search to find entries. For this reason, you should only use COLLECT to fill standard tables.

- SORTED TABLE:
The system uses a binary search to find the entries. There is a logarithmic relationship between the number of table entries and the search time.

(Continued on next question...)

Other Interview Questions