While working with Internal tables you need to consider the following cases:
You want to reorganize the contents of table. You want to modify few details of table and then display the contents of table to user. You want to perform table calculations on subset of database table.
In ABAP/4 you work mainly with tables. Long life data is stored in database tables. You cannot afford to lose data from database table. In such cases where you cannot work directly with database table (where you are modifying contents of table or reorganizing the contents of table or any other case where you are altering contents of table and then displaying output to the user) hence need of intermediate table where you put in all the data from database table and work with this data thus avoiding accidental loss of data.
These intermediate tables are called INTERNAL TABLES in ABAP/4 and are created only during runtime( do not confuse this with dynamic internal tables) i.e., no memory is reserved for internal tables.
When you use Internal Table in a program, three steps are associated with it.
Declaration of Internal Table Populating Internal Table Processing Internal Table
Declaration of Internal Table
Depending on how you create, internal tables are of two types.
Internal tables with header line. When you create internal tables with header line, and then default workarea or header is created. And you can work with this header. Internal Table without header line. In this case you need to create output explicit workarea to work with table. Only advantage of internal tables without header line is that you can nest them i.e., you can have table within table, which is not possible on internal tables with header line.
Internal table can be declared in the following way:
Data: Itab like sflight occurs 0 with header line.
Here you are declaring internal table, which is similar to sflight i.e., itab like sflight i.e., you are referring to existing table. By default internal table created with this declaration is without header line.
Data:Begin of itab occurs 0. Include structure sflight Data:End of itab
Internal Table created with this type of declaration is similar to declaration done in ‘a’ type the only difference is by default internal table created by this type is with header line,
Data:Begin of itab occurs 0 carrid like sflight-carrid, connid like sflight-connid, fldate like sflight-f1date End of itab.
By default internal table created by this type of declaration is with header line. In this type of declaration, you are using only those fields from database table, which you require for processing.
Data:Begin of itab occurs 0 carrid like sflight-carrid, connid like sflight-connid, bookid like sbook-bookid id like scustom-id, End of itab.
Here you are combining fields from three different tables in one internal table.
Data:Begin of itab occurs 0 Carrid1 like sflight-carrid, End of itab.
Here you are specifying different field names. Populating Internal Table.
Itab-name = ‘ABCD’. Append Itab.
In the above case itab is filled with one name i.e., ‘ABCD’.
Do 5 times. Itab-number = sy-index. Append itab. Enddo.
In the above case itab is filled with sy-index for 5 times)
Select * from sflight into itab. Append itab. Endselect.
Select * from sflight into table itab.
Note: Addition of Table in INTO clause, you omit append itab and Endselect
Select * from sflight Move-corresponding sflight to itab. Append itab. Endselect.
Note: While using Move-corresponding, field names of DB table & Int’ table should be same.
Select * from sflight. Move sflight to itab. Append itab. Endselect.
Note: In this case structure of sflight and itab should be similar
Select carrid1 connid1 from sflight into (itab-carr1, itab-connid1) Append itab. Clear itab. Endselect.
Social Plugin