Difference between Append and Insert

Introduction

Before discussing the difference between APPEND and INSERT, let’s have a short introduction of the two.

Internal tables are used to process the data dynamically during the program execution. Data is populated to the internal table during runtime i.e. program execution.

APPEND and INSERT are the 2 statements that are used to populate the internal table.

In this article we will explore more about the Difference between Append and Insert.

Append

APPEND statement adds one or more records at the end of the existing internal table.

Syntax:

APPEND {<work-area>| INITIAL LINE |LINES OF jtab [FROM idx1] [TO idx2]} TO <itable>.

<work-area> adds the contents of the work area  <work-area> to the internal table <itable>.

INITIAL LINE appends a blank line to the internal table <itable> with initial values in each field according to the definition.

LINES OF jtab [FROM idx1] [TO idx2] appends the rows from idx1 index to idx2 index from jtab to the internal table <itable>.

The APPEND statement sets sy-tabix with the index of the last appended row.

Insert

INSERT statement adds one or more records at a specified position of the internal table. The position can be specified by the primary table key or a table index.

Syntax:

INSERT {<work-area>| INITIAL LINE | LINES OF jtab [FROM idx1] [TO idx2]} TO <itable> [INDEX <idx>].

<work-area> adds the contents of the work area  <work-area> to the internal table <itable>.

INITIAL LINE appends a blank line to the internal table <itable> with initial values in each field according to the definition.

LINES OF jtab [FROM idx1] [TO idx2] appends the rows from idx1 index to idx2 index from jtab to the internal table <itable>.

INDEX specifies the position of the internal table where the new record has to be added. If the Index is not specified, the system adds the new record at the end of the internal table. If the internal table has a record at the specified index, then the new record is added at the specified index and the existing record is reinserted by incrementing the index by 1.

The INSERT statement does not set the system field sy-tabix.

Difference between Append and Insert

Now, let’s have a look at their difference.

 

 

 

APPEND INSERT
It is a statement that is used to add a record at the end of an internal table. It is a statement that is used to add/insert record at a specific position of Internal Table.
New records are always added to the end of the internal table. If the position is not specified only then the new records are added to the end of the internal table.
System field SY-TABIX is set to the index of the last appended row. System field  SY-TABIX is not set.

 

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.