SAP
Difference between ...
Notifications
Clear all

Difference between Collect and Sum

RSS

(@sathish)
Member Moderator
Joined: 2 years ago
Posts: 1391
30/03/2021 12:17 pm

Difference between Collect and Sum ?


Quote
(@sathish)
Member Moderator
Joined: 2 years ago
Posts: 1391
30/03/2021 12:17 pm

SUM

When processing an internal table in a block startingwith LOOPand concludedby ENDLOOP,SUM calculatesthe control totals of all fields of typeI, F and Pand places them in the LOOP output area (header line of the internal table or an explicitly specified work area).

When you useSUM in a LOOPwith an explicitly specified output area, this output area must be compatible with the line type of the internal table. When using LOOP to process a sorted extract, the control total of f at the end of the group appears in the field SUM(f) - - if f is type I, F or P.

COLLECT

COLLECTis used to create unique or compressed datsets. The key fields are the default key fields of the internal table itab.

If you use only COLLECT to fill an internal table,COLLECTmakes sure that the internal table does not contain two entries with the same default key fields.

If, besides its default key fields, the internal table contains number fields,the contents of these number fields are added together if the internal table already contains an entry with the same key fields.

If the default key of an internal table processed withCOLLECT is blank,all the values are added up in the first table line.

If you specify wa INTO, the entry to be processed is taken from the explicitly specified work area wa. If not, it comes from the header line of the internal table itab.

AfterCOLLECT,the systemfield SY-TABIXcontains the index of the - existing or new - table entry with default key fields which match those of the entry to be processed.

COLLECTcan create unique or compressed datasets and should be used precisely for this purpose. If uniqueness or compression are unimportant, or two values with identical default key field values could not possibly occur in your particular task, you should useAPPENDinstead. However, for a unique or compressed dataset which is also efficient, COLLECT is the statement to use.

If you process a table with COLLECT, you should also use收集来填补it.Only by doing this can you guarantee that the internal table will actually be unique or compressed, as described above and COLLECT will run very efficiently.

If you use COLLECT with an explicitly specified work area, it must be compatible with the line type of the internal table.

COLLECT allowsyou 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 are added to the sum total of the existing entries. If it does not find an entry, the system creates a new entry instead.


ReplyQuote
Share:
Baidu