Summary -

In this topic, we described about the below sections -

The APPEND statement adds a single line/row to an existing internal table. APPEND statement uses the work area to append the line/row information into the table.

APPEND inserts the data after the last line of the internal table. The work area can be either a header line or any other line with the same structure as an internal table.

Syntax -

APPEND [<work-area>/INITIAL LINE] TO <itable>.

  • <wrok-area> - Specifies the work area.
  • itable - Specifies the internal table name.

If the user uses the work area <work-area>, the SAP system adds a new line to the internal table <itable> with the content of work area <work-area>. If the user uses the INITIAL LINE clause, the blank line appends to the table with the initial values in each field according to the definition.

The SY-TABIX variable contains the index number of the appended line after each APPEND statement. For standard tables, appending lines with a non-unique key always successful regardless of the duplicates exists in the table or not. i.e., duplicate rows can be inserted.

For sorted tables, appending lines with a non-unique key always successful regardless of the duplicates exists in the table or not. i.e., duplicate rows can be inserted. Appending lines to sorted table with a unique key throws runtime error if the user attempts to append the line with a duplicate key. It also throws runtime error if user violates the sort order of sorted table.


Example -

Simple example to insert the data using APPEND to the product information internal table with below structure.

Pid -Character (10)
Pname - Character (40)
Pamount - Decimal (10)


Code -

*&---------------------------------------------------------------------*
*& Report  Z_INTERNAL_TABLE
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*

REPORT  Z_INTERNAL_TABLE.

* Internal table Structure creation
TYPES: BEGIN OF t_product,
       pid(10)     TYPE C,
       pname(40)   TYPE C,
       pamount(10) TYPE P,
       END OF t_product.

* Data & internal table declaration
DATA: wa TYPE t_product,
      it TYPE TABLE OF t_product.

wa-pid     = 'IFB1'.
wa-pname   = 'IFB WASHING MACHINE'.
wa-pamount = 31000.

* Appending data to the internal table
APPEND wa TO it.

* Reading internal table of index 1
READ TABLE it INTO wa INDEX 1.

* If sy-subrc equal to ZERO, the internal table read is successful.
* Otherwise, 'No Record Found' gets displayed.
IF sy-subrc = 0.
  WRITE: wa-pid, wa-pname, wa-pamount.
ELSE.
  WRITE 'No Record Found'.
ENDIF.

Output -

Append Statement Example Output

Explaining Example -

In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.

t_product - Structure declaration, wa - work area of type t_product and it - internal table declaration of type t_product.

APPEND wa TO it. - Appending work area(wa) to the table(it) and READ TABLE it INTO wa INDEX 1. - Reading internal table with index 1.