What is the difference between collect and sum?

Showing Answers 1 - 4 of 4 Answers

Tamseel Hashmi

  • Aug 1st, 2006
 

SUM.

When processing an internal table in a block starting with LOOP and concluded by ENDLOOP , SUM calculates the control totals of all fields of type I , F and P (see also ABAP/4 number types ) and places them in the LOOP output area (header line of the internal table or an explicitly specified work area).

When you use SUM in a LOOP with 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 (see SORT ), 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.

COLLECT is 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, COLLECT makes 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 with COLLECT 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 .

After COLLECT , the system field SY-TABIX contains the index of the - existing or new - table entry with default key fields which match those of the entry to be processed.


COLLECT can 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 use APPEND instead. 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 COLLECT to fill 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.

  Was this answer useful?  Yes

GNANESH

  • Oct 23rd, 2006
 

COLLECT : IT MEANS THAT IT WILL ADD UP THE NUMBERS AND GIVE U GRAND TOTAL, WHERE AS SUM MEANS IT WILL ADDUP

  Was this answer useful?  Yes

Lakshmandr

  • Mar 19th, 2007
 

HI,
 Collect statement is using as append statement and as well as sum statement, means whenever collect statement will encountered then first it checks whether that record exist in the interna table with the same key or not. If yes then add that else append at the end of internal table. 
 But sum is only for sum the values.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions