In SAP, ABAP has three types of data inserted into internal tables: APPEND, COLLECT, and INSERT.
To fill the inner table, you can add data row by row or copy the content of another table.
You can use the APPEND, COLLECT, or INSERT statement to populate the inner table row by row.
_ To use an internal table only for data storage, we recommend that you use APPEND for performance considerations. You can also use APPEND to create a sequence list.
_ To calculate the sum of several word fields or to ensure that no duplicate entries exist in the internal table, use the COLLECT Statement, which is based on the standard key word processing line.
_ To INSERT a new row before existing rows in the internal table, use the INSERT statement.
To copy the internal table capacity to another internal table, use the variant of the APPEND, INSERT, or MOVE statement.
_ To attach rows from the inner table to another inner table, use the variant of the APPEND statement.
_ To INSERT rows from the inner table into another inner table, use the variant of the INSERT statement.
_ To reproduce the content of an inner table entry to another inner table and overwrite the table, use the MOVE statement.
COLLECT features let me see the dawn of Enterprise report writing. Sometimes we need to summarize the annual turnover of a region or a customer, so COLLECT is very useful. We don't even need to judge whether this record exists like QAD, SAP has helped you deal with all this!
However, by default, COLLECT only summarizes non-P and I, which sometimes makes a lot of inconvenience. Leave the next blog article to solve this problem! See the following example:
REPORT Z_COLLECT.
DATA: begin of itab occurs 4,
COLUMN1 (3) type c,
COLUMN2 (2) type n,
COLUMN3 type I,
COLUMN4 (5) type c,
End of itab.
ITAB-COLUMN1 = 'abc'. ITAB-COLUMN2 = '12'. ITAB-COLUMN3 = 3. ITAB-COLUMN4 = 'xyz '.
Collect itab.
WRITE/SY-TABIX.
ITAB-COLUMN1 = 'def '. ITAB-COLUMN2 = '34'. ITAB-COLUMN3 = 5. ITAB-COLUMN4 = 'xyz '.
Collect itab.
WRITE/SY-TABIX.
ITAB-COLUMN1 = 'abc'. ITAB-COLUMN2 = '12'. ITAB-COLUMN3 = 15. ITAB-COLUMN4 = 'xyz '.
Collect itab.
WRITE/SY-TABIX.
Loop at itab.
WRITE:/ITAB-COLUMN1, ITAB-COLUMN2, ITAB-COLUMN3, ITAB-COLUMN4.
ENDLOOP.
Result:
1
2
1
Abc 12 18 xyz
Def 34 5 xyz
Have you understood this result ??