ABAP INSERT into Table statement

INSERT statement is used for inserting items in Database Tables, Index tables, Internal Tables, Field Groups etc in our ABAP programs. Here we are going to refer about the INSERT statement with tables. For tables INSERT statement will insert new lines in the specified data base tables or internal tables. Now let us check for the syntax and variations.

Insert into DATABASE Tables

Syntax

INSERT <dbtab> FROM <wa>.

INSERT <dbtab> FROM TABLE <itab> [ACCEPTING DUPLICATE KEYS].

  • First INSERT statement will insert the lines from the work area (<wa>) into the specified database table (<dbtab>)
  • Second INSERT statement will insert the lines from an internal table into the specified database table.
  • ACCEPTING DUPLICATE KEYS addition is used for specifying the duplicate entries are allowed or not. By adding this addition it will add the new entries with the same keys already exist in database table (Duplication allowed). By default duplicate entries will produce a run-time error. We can ignore this by adding this variation.

Insert into Internal tables

Syntax

INSERT <line>|LINES OF <jtab> [FROM <n1>] [TO <n 2>]

INTO TABLE <itab>

[ASSIGNING <FS> | REFERENCE INTO <dref>].

  • This statement will insert the lines into an internal table from another internal table.
  • FROM and TO addition will specify the lines to add from the internal table (For example we can specify add the lines from 10th to 20th from an internal table to another internal table).It is an optional one and used for restricting the lines.
  • ASSIGNING and REFERENCE INTO addition is used for assigning the inserted record into a field symbol.

Here is a sample ABAP program structure with INSERT statement

Also Read : View Other ABAP Keywords & Syntax -> ABAP Transaction codes