Internal Tables Theory
Internal Tables Theory
Internal Tables Theory
Internal table is a temporary table that contains the records of an ABAP program while it is
being executed.
It exists only during the execution of the program. So the records are discarded when the
program terminates.
It is declared in an ABAP program when u need to retrieve the data from database tables.
It stores data in the form of rows and columns.
Individual rows are accessed by index or a key.
WorkArea:
OR
DATA: <itab_name> TYPE TABLE of <DBtable name> OCCURS 0 WITH HEADER LINE. -no work area will
be used here so no need to create 1 exclusively. Occurs 0 means initial size of itab is 8 kb and then it
increases.
OR
Var1 type I,
var2 type I
END OF itab_name.
Wa TYPE itab_name.
OR
TYPES : BEGIN OF struct_name,
Var1 type I,
var2 type I
END OF struct_name.
OR
insert wa INTO TABLE itab also insert wa INTO TABLE itab also Only insert wa INTO TABLE itab
works. works. works.
1. Append : Used to add 1 single record from workarea to internal table. Record is added at the
bottom.
APPEND wa INTO itab.
Loop syntax:
LOOP AT i_table INTO wa.
2. INSERT : Used to insert record from a workarea to internal table at a specified location.
INSERT wa INTO itab INDEX indexno.
insert wa1 into table stud1. (CANNOT WRITE INDEX NO here)
3. CLEAR: Used to delete the data from workarea(WA).
CLEAR wa_name.
FREE internal_tablename/wa.
FREE is used to clear (free) memory of an internal table or work area. We all know
whenever we declare an internal table or work area, 8kb memory will be allocated.
6. READ : 3 Ways of reading from workarea- loop , index and key(Hash tables can be read only by
key and loop).
READ TABLE stud1 into wa1 index 2.
9. COLLECT: Used for inserting components of workarea into internal table by avoiding duplicates
and also in summarized way.
o First it will check in internal table for any record matching with the key in work area
data.
o COLLECT is used to summate numerical entries in an internal table
by looking all other non-numeric values. If all non-numeric values
are same it sums up numeric values and updates proper record, but
if any non-numeric field is not same it appends a new record.
o Collect statement calculates the sub total of non-character
fields(P,I,F) by taking character fields as key. In case all fields are of
only character type then it will work similar to the append
statement.
10. SUM.
The statement SUM can only be specified within a loop starting with LOOP, and is only
considered within a AT-ENDAT control structure. Prerequisites for using the statement
SUM include using the addition INTO in the LOOP statement, and that the specified
work area wa is compatible with the row type of the internal table. In addition, SUM
cannot be used when the row type of the internal table itab contains components that are
tables.
The statement SUM calculates the sums of the components with numerical data type of
all rows in the current group level and assigns the sums to the components of the work
area wa. In the control levels FIRST, LAST, and outside of an AT-ENDAT control
structure, the system calculates the sum of numeric components of all rows in the internal
table.
11. At operations
o At First…. EndAt.
o At Last …EndAt.
o At New <fieldname>… EndAt .
o At End OF <fieldname>….EndAt.
o On Change Of <fieldname>…. End on. ( LHS rule does not apply rather if the
field changes the statement gets executed.