Internal Table Operations in ABAP

Append

APPEND: statement is used to append or add a record from the work area to the internal table; the new record will be added at the end of the internal table

*APPEND OPERATION
*It adds a row at last postion of the internal table
wa_ekko-ebeln = '5000000000' .
wa_ekko-bukrs = '1710' .
wa_ekko-bstyp = 'F' .

APPEND wa_ekko to it_ekko .

Insert

INSERT statement is used to insert or add a record from work area into internal table at the specified location

*INSERT OPERATION
*It add a row at specified  postion of the internal table

wa_ekko-ebeln = '5000000003' .
wa_ekko-bukrs = '1717' .
wa_ekko-bstyp = 'P' .

INSERT wa_ekko INTO it_ekko INDEX 2 .

Delete

To delete the records of the Internal Table.

*Delete
*to delete single record
Delete it_ekko2 INDEX 2 .
*to delete range of record
Delete it_ekko2 FROM 2 to 4 .

Modify

MODIFY is used to modify a single or multiple internal table records based on a condition

TRANSPORTING is a keyword that is used to specify a list of fields to be modified instead of all fields.

Describe

DESCRIBE TABLE is used to count the no of records in an internal table

DATA : V_LINES TYPE I. "Type integer
DESCRIBE TABLE IT_MARA LINES V_LINES . " Count the no. of record of a internal table

Write: v_lines .

Sort

SORT is used to sort Internal table data in ascending order or descending order. By default, it will sort the data in ascending order. In addition to this, we can sort data based on specified fields

Read

READ TABLE WITH KEY .. BINARY SEARCH is used to read a single record from an internal table into a work area specified by field name and field value.

BINARY SEARCH is a search mechanism that is used to read a record from the internal table into a work area very fast, the functionality of binary search is to divide the into parts and search, for full details Binary Search mechanism in SAP ABAP.

Refresh / Clear / Free

CLEAR is used to clear a value in a work area or a variable.

REFRESH is used to clear all values in an internal table.

FREE is used to clear (free) memory of an internal table or work area. We all know that whenever we declare an internal table or work area, 8 KB of memory will be allocated.

Loop…Endloop

 to print/process the multiple records sequentially.

Complete Programme

*&---------------------------------------------------------------------*
*& Report ZINTOPERATION
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zintoperation.

TYPES : BEGIN OF ty_ekko ,

          ebeln	TYPE ebeln,
          bukrs TYPE  bukrs,
          bstyp TYPE  ebstyp,

        END OF ty_ekko .

DATA : it_ekko TYPE TABLE OF ty_ekko .
DATA : wa_ekko TYPE  ty_ekko .

*APPEND OPERATION
*It adds a row at last postion of the internal table
wa_ekko-ebeln = '5000000000' .
wa_ekko-bukrs = '1710' .
wa_ekko-bstyp = 'F' .

APPEND wa_ekko TO it_ekko .

wa_ekko-ebeln = '5000000001' .
wa_ekko-bukrs = '1711' .
wa_ekko-bstyp = 'D' .

APPEND wa_ekko TO it_ekko .

wa_ekko-ebeln = '5000000002' .
wa_ekko-bukrs = '1710' .
wa_ekko-bstyp = 'G' .

APPEND wa_ekko TO it_ekko .

*How to add multiple row into an internal table

DATA it_ekko2 TYPE TABLE OF ty_ekko .

APPEND LINES OF it_ekko TO it_ekko2.


*INSERT OPERATION
*It add a row at specified  postion of the internal table

wa_ekko-ebeln = '5000000003' .
wa_ekko-bukrs = '1717' .
wa_ekko-bstyp = 'P' .

INSERT wa_ekko INTO it_ekko INDEX 2 .



INSERT LINES OF it_ekko FROM 2 TO  5 INTO it_ekko2 INDEX 1.



*Delete
*to delete single record
DELETE it_ekko2 INDEX 2 .
*to delete range of record
DELETE it_ekko2 FROM 2 TO 4 .


WRITE:/ 'IT_EKKO2 Data'.

LOOP AT it_ekko2 INTO wa_ekko .


  WRITE :/  wa_ekko-ebeln   , ' ' , wa_ekko-bukrs , ' ' ,wa_ekko-bstyp  .

ENDLOOP .

Scroll to Top