SAP Internal Tables
SAP Internal Tables
SAP Internal Tables
In this tutorial we will cover the following topics Internal Tables . Difference between Internal Tables and Work Areas Types of Internal Tables Creating Internal Tables Populating Internal Tables Reading Internal Tables Deleting from Internal table.
Lets Begin!
1. Internal tables with HEADER line 2. Internal tables without HEADER line. Internal Tables with Header Line Here the system automatically creates the work area. The work area has the same data type as internal table. This work area is called the HEADER line. It is here that all the changes or any of the action on the contents of the table are done. As a result of this, records can be directly inserted into the table or accessed from the internal table directly. Internal Tables without Header Line : Here there is no work area associated with the table. Work area is to be explicitly specified when we need to access such tables. Hence these tables cannot be accessed directly.
You can create an internal table by referring to an existing table. The existing table could be a standard SAP table, a Z table or another internal table. Syntax-
Data : Begin of itab occurs 10, column1 type I, column2(4) type C, column3 like mara-ernam, End of itab.
Internal table itab is created
1.Append Data line by line The first method available is the use of the APPEND statement. Using the APPEND statement we can either add one line from another work area to the internal table or we can add one initial line to the internal table.. Syntax -
Data: Begin of itab occurs 10, col1 type C, col2 type I, end of itab. Append initial line to itab.
Results : 0 Initial lines adds a line initialized with the correct value for its type to the table. Here , col1 is an integer and col2 is a character. Then APPEND initial line , adds a line initialized with respect to the data type of the columns, i.e. 0 for Col1 and space for Col2. 2.Using COLLECT statement COLLECT is another form of statement used for populating the internal tables. Generally COLLECT is used while inserting lines into an internal table with unique standard key. Syntax-
itab1[] = itab2[].
1.Deleting lines in a loop. This is the simplest way for deleting lines. Sytax
DELETE <ITABLE>.
This statement works only within a loop. It deletes the current line. You can delete the lines in a loop conditionally by adding the WHERE clause. 2.Deleting lines using the index. This is used to delete a line from internal table at any know index. Syntax