Internal Tables in SAP ABAP
Internal tables are an important part of any ABAP development.
Basically we will see what the following statements do to an internal table.
REFRESH
FREE
Consider an Internal table with name ITAB.
CLEAR ITAB[]
The above statement will clear the contents of the internal table but the header line contents will not be cleared.
REFRESH ITAB
The above statement will also clear the contents of the internal table completely. If the table has a header line the contents of the header line will still remain. This is used when the internal table is without the header line.
FREE ITAB
Will deallocate the memory for the internal table. For better performance of ABAP programs you
DELETE
You can use DELETE statement to delete a particular record from the internal table.
Examples
CLEAR ITAB.
VBELN KUNNR MATNR WERKS
00010 7777 A123 1000
00020 7777 B122 1000
00030 7777 C506 1000
00040 7777 D777 1000
and the header line contents are as follows
Header Line <00010 7777 A123 1000>
Note: CLEAR ITAB will clear only the contents of the header line. and the ITAB values will remain as shown
ITAB
VBELN KUNNR MATNR WERKS
00010 7777 A123 1000
00020 7777 B122 1000
00030 7777 C506 1000
00040 7777 D777 1000
Header Line < >
CLEAR ITAB[]
VBELN KUNNR MATNR WERKS
<>
Header Line
Header Line <00010 7777 A123 1000>
REFRESH
Will clear the header line as well as the contents of ITAB
VBELN KUNNR MATNR WERKS
Header Line <00010 7777 A123 1000>
Header Line
<>
FREE ITAB
Will clear the contents of the ITAB as shown above for REFRESH and CLEAR in addidtion to that it also frees
Header Line <00010 7777 A123 1000>
DELETE
If you just want to delete a particular row then you need to use the DELETE statement.
DELETE ITAB INDEX IDX.
SY_SUBRC = 4 The entry does not exist.
Consider a case when your internal table has duplicate entries, in this situation you can SORT the internal
SORT ITAB
DELETE ADJACENT DUPLICATES FROM ITAB.
COMPARING field1 field2
COMPARING ALL FIELDS
CLEAR ITAB
CLEAR ITAB[]
REFRESH ITAB
FREE ITAB
contents of the ITAB keeping the header line contents intact. This will also dealocate the internal table from the SAP memory.
Then you need to delete the duplicates as shown below
DELETE ADJACENT DUPLICATES FROM ITAB
Also
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING field1 field2
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS