In this topic, we described about the below sections -
What is Internal Table?
Internal table is a temporary table that is created and used during the program execution and deleted before the program terminated. Internal tables used to store the dynamic data that sets from a fixed structure in the main/working memory in ABAP.
The life time of the table is until end of the program execution. Internal tables fulfill the function of arrays in ABAP. Internal tables are the most complex data objects in ABAP environment.
An important use for internal tables is storing and formatting data from a database table within a program.
How Data is stored in Internal Tables?
Data in the internal table stores as a rows and columns. The rows in the internal table called as lines. The columns called as fields.
All the lines in the internal table has the same key and same structure. The records inserted into the internal table exits till the end of the program execution.
Once the program terminated, internal table and the data associated with it are discarded. The structure can contain only one line of data. But the table contains multiple lines of the data with the same structure.
The number of lines or the size of the internal tables are not fixed. The size of the internal table may vary from program to program based on the requirement. But these internal tables are stored in main memory. So it is always good practice to maintain these tables size as small to avoid using the main memory more that may cause system running slow.
Internal tables are specified by below four properties -
- Table type determines the access type that specifies how ABAP accesses the individual table rows.
- Row type determines the column that is declared with any ABAP data type.
- Uniqueness of the key specifies the key as unique or non-unique.
- Key components specify the criteria based on which the table rows are identified.
Internal Table Types -
There are three types of internal tables in SAP ABAP programming. Those are -
- Standard Internal Tables
- Sorted Internal Tables
- Hashed Internal Tables
Difference between Internal Tables -
|Standard Internal tables||Sorted Internal Tables||Hashed Internal tables|
|These are default internal tables.||These are a special type of internal tables, where data is automatically sorted when the record is inserted||These are used with logical databases|
|It is an index table||It is an index table||It is not an index table|
|Table has non-unique key||Table has unique key||Table key is unique and no duplicate entries allowed.|
|Either key or index operation used to read a record.||Either key or index operation used to read a record.||Key operation used to read the record.|
Index operation is not allowed.
|Either linear search or binary search used to search for a record||Binary search used to search for a record||Hashed algorithm used to search for a record|
|Data is not sorted by deafult and can use sort operation to sort the data.||Data already sorted.||Data already sorted.|
|Records can be inserted or appended.||Records can be inserted||Used in ABAP with BI projects|
Header Line -
Header line plays key role to inform the system on whether the work area should create automatically or not . Header line is an optional parameter while declaring the internal table.
Internal table can be created in two ways and those are -
- Internal Tables with Header Line
- Internal Tables without Header Line
Internal Tables with Header Line -
- System automatically creates the work area.
- The work area has the same data type as internal table declaration.
- Work area is called as HEADER line.
- The data automatically places to work area if any read operations performed on internal table.
- The data loaded from work area if any insertion or modify operations performed on internal table.
Internal Tables without Header Line -
- No work area associated with the table.
- Work area is to be explicitly specified when accessing tables.
- Tables cannot accessed directly.