If You Want To Be A Winner, Learn About INTERNAL TABLES IN ABAP Now!

Updated: May 31



INTERNAL TABLES


Internal table is actually a temporary table, which contains the records of an ABAP program that it is being executed. An internal table exists only during the run-time of a SAP program. They are used to process large volumes of data by using ABAP language. We need to declare an internal table in an ABAP program when you need to retrieve data from database tables.


Internal tables only exist when a program is running, so when the code is written, the internal table must be structured in such a way that the program can make use of it. You will find that internal tables operate in the same way as structures. The main difference being that structures only have one line, while an internal table can have as many lines as required.

The size of an internal table or the number of lines it contains is not fixed. The size of an internal table changes according to the requirement of the program associated with the internal table. But it is recommended to keep internal tables as small as possible. This is to avoid the system running slowly as it struggles to process enormous amounts of data.


Internal tables are used for many purposes −

  • They can be used to hold results of calculations that could be used later in the program.


  • An internal table can also hold records and data so that this can be accessed quickly rather than having to access this data from database tables.


SYNTAX—>

DATA : INTERNAL_TABLE_NAME TYPE STANDARD TABLE OF

DATABASE_TABLE_NAME / STRUCTURE_NAME,

WORK_AREA TYPE DATABASE_TABLE_NAME / STRUCTURE_NAME.

TYPES OF INTERNAL TABLES—>

  1. STANDARD INTERNAL TABLE

  2. SORTED INTERNAL TABLE

  3. HASHED ITERNAL TABLE


WORK AREA—> A work area in ABAP represents single row of an internal table and it is used to process internal table line by line. It holds only single data at runtime. By using work area we can add, delete, modify the multiple records one by one.


CONVENTION—>

Name of the internal table should always be in the form of IT_DB_TABLE or LT_DB_TABLE.

CREATION OF INTERNAL TABLE


STEP 1—> Open the ABAP Editor by executing the SE38 transaction code. The initial screen of ABAP Editor appears.

STEP 2—> In the initial screen, enter a name for the program, select the Source code radio button and click the Create button to create a new program.

STEP 3—> In the 'ABAP: Program Attributes' dialog box, enter a short description for the program in the Title field, select the 'Executable program' option from the Type drop-down menu in the Attributes group box. Click the Save button.

STEP 4—> Write the code in ABAP Editor.


CODING SCREEN—>



OUTPUT—>



INTERNAL TABLE OPERATIONS

  1. APPEND—> The APPEND statement is used to add a single row or line to an existing internal table. This statement copies a single line from a work area and inserts it after the last existing line in an internal table. The work area can be either a header line or any other field string with the same structure as a line of an internal table.

SYNTAX—>


APPEND WORK_AREA TO INTERNAL_TABLE.


CODING SCREEN—>



OUTPUT—>


2. INSERT—> INSERT statement is used to insert a single line or a group of lines into an internal table. A new line can be inserted by using the work_area_itab INTO expression before the internal_tab parameter. When the work_area_itab INTO expression is used, the new line is taken from the work_area_itab work area and inserted into the internal_tab table. However, when the work_area_itab INTO expression is not used to insert a line, the line is taken from the header line of the internal_tab table.


When a new line is inserted in an internal table by using the INDEX clause, the index number of the lines after the inserted line is incremented by 1. If an internal table contains <index_num> - 1 lines, the new line is added at the end of the table. When the SAP system successfully adds a line to an internal table, the SY-SUBRC variable is set to 0.

SYNTAX—>


INSERT WORK_AREA INTO INTERNAL_TABLE INDEX INDEX_NUM.


CODING SCREEN—>



OUTPUT—>


3. MODIFY—> It is used to modify a particular field value based on another field value.


SYNTAX—>


MODIFY INTERNAL_TABLE FROM WORK_AREA TRANSPORTING FFIELD WHERE CONDITION.


CODING SCREEN—>



OUTPUT—>



4. DELETE—> The DELETE statement is used to delete one or more records from an internal table. The records of an internal table are deleted either by specifying a table key or condition or by finding duplicate entries. If an internal table has a non-unique key and contains duplicate entries, the first entry from the table is deleted.


SYNTAX—>

DELETE INTERNAL_TABLE FROM INDEX TO INDEX.


CODING SCREEN—>


OUTPUT—>



To delete a specific record—>

DELETE IT_MARA WHERE CONDITION.


CODING SCREEN—>



OUTPUT—>



5. SORT—> It is used to sort the data either in ascending or descending order.

SYNTAX—>


SORT INTERNAL_TABLE BY FIELD_NAME ASCENDING.

SORT INTERNAL_TABLE BY FIELD_VALUE DESCENDING.

CODING SCREEN—>



OUTPUT—>



CODING SCREEN—>


OUTPUT—>



6. DELETE ADJACENT DUPLICATES—> It is used to delete adjacent duplicate records from internal table. For deleting duplicate records we first have to sort the table either in ascending or descending order.


SYNTAX—>


DELETE ADJACENT DUPLICATES FROM INTERNAL_TABLE COMPARING ALL FIELDS.


CODING SCREEN—>



OUTPUT—>



SHORTCUT TO CREATE A STRUCTURE—>

  1. Click on PATTERN.

2. Select the radio button “WITH FIELDS” under the heading “STRUCTURED DATA OBJECT”.



3. Search for the database table.