6 Columns with Active Background
6 Columns with Active Background
Active List Item Background

24DDIC2607 – Internal Table Operations Insert, Modify, and Delete Data Using Keywords

In the realm of ABAP programming, internal tables are powerful tools that allow developers to manage and manipulate data in memory efficiently. Understanding how to use keywords to insert, modify and delete data in these internal tables is crucial for creating robust and effective applications. This blog post will guide you through the essentials of managing internal tables using key ABAP keywords.

Inserting Data

In ABAP, inserting data into an internal table is straightforward and can be achieved using the ‘INSERT’ keyword. When working with internal tables, you typically define the table with a structure or a type and then use ‘INSERT’ to add new entries.

Here’s a basic example:

DATA: lt_my_table TYPE TABLE OF my_structure,

      ls_my_data  TYPE my_structure.

ls_my_data-field1 = ‘Value1’.

ls_my_data-field2 = ‘Value2’.

INSERT ls_my_data INTO TABLE lt_my_table.

 

In this example, ‘lt_my_table’ is an internal table of type ‘my_structure’, and ‘ls_my_data’ is a work area. The ‘INSERT’ statement adds ‘ls_my_data’ to ‘lt_my_table’.

 

Modifying Data

Modifying data in an internal table is also managed by a specific keyword: ‘MODIFY’. This keyword is used when you want to update existing records. It can be used to modify all entries or a specific entry if you provide a condition.

For instance:

DATA: lt_my_table TYPE TABLE OF my_structure,

      ls_my_data  TYPE my_structure.

” Assume lt_my_table is already populated with data

ls_my_data-field1 = ‘NewValue’.

MODIFY lt_my_table FROM ls_my_data.

 

Here, ‘MODIFY’ updates the existing records in ‘lt_my_table’ with the values in ‘ls_my_data’. By default, it updates all entries that match the primary key of ‘ls_my_data’.

To modify specific entries based on conditions, you can use the ‘MODIFY’ statement with a ‘WHERE’ clause:

MODIFY lt_my_table TRANSPORTING field1 WHERE field2 = ‘SomeCondition’.

This command updates the ‘field1’ of entries where ‘field2’ matches ‘SomeCondition’.

Deleting Data

Deleting records from an internal table is handled using the ‘DELETE’ keyword. Similar to modifying, you can delete all matching records or specific entries based on conditions.

DATA: lt_my_table TYPE TABLE OF my_structure.

” Assume lt_my_table is already populated with data

DELETE lt_my_table WHERE field1 = ‘ValueToRemove’.

 

In this case, the ‘DELETE’ statement removes entries from ‘lt_my_table’ where ‘field1’ is ‘ValueToRemove’. If you want to delete a single entry, you would typically use an index:

 

DATA: lv_index TYPE sy-tabix.

lv_index = 2. ” Index of the entry to be deleted

DELETE lt_my_table INDEX lv_index.

 

Here, ‘DELETE’ removes the entry at position 2 of ‘lt_my_table’.

 

Author : Aniket Pawar, 9373518385                                                     

24DDIC2607 – Internal Table Operations Insert, Modify, and Delete Data Using Keywords

In the realm of ABAP programming, internal tables are powerful tools that allow developers to manage and manipulate data in memory efficiently. Understanding how to use keywords to insert, modify and delete data in these internal tables is crucial for creating robust and effective applications. This blog post will guide you through the essentials of managing internal tables using key ABAP keywords.

Inserting Data

In ABAP, inserting data into an internal table is straightforward and can be achieved using the ‘INSERT’ keyword. When working with internal tables, you typically define the table with a structure or a type and then use ‘INSERT’ to add new entries.

Here’s a basic example:

DATA: lt_my_table TYPE TABLE OF my_structure,

      ls_my_data  TYPE my_structure.

ls_my_data-field1 = ‘Value1’.

ls_my_data-field2 = ‘Value2’.

INSERT ls_my_data INTO TABLE lt_my_table.

 

In this example, ‘lt_my_table’ is an internal table of type ‘my_structure’, and ‘ls_my_data’ is a work area. The ‘INSERT’ statement adds ‘ls_my_data’ to ‘lt_my_table’.

 

Modifying Data

Modifying data in an internal table is also managed by a specific keyword: ‘MODIFY’. This keyword is used when you want to update existing records. It can be used to modify all entries or a specific entry if you provide a condition.

For instance:

DATA: lt_my_table TYPE TABLE OF my_structure,

      ls_my_data  TYPE my_structure.

” Assume lt_my_table is already populated with data

ls_my_data-field1 = ‘NewValue’.

MODIFY lt_my_table FROM ls_my_data.

 

Here, ‘MODIFY’ updates the existing records in ‘lt_my_table’ with the values in ‘ls_my_data’. By default, it updates all entries that match the primary key of ‘ls_my_data’.

To modify specific entries based on conditions, you can use the ‘MODIFY’ statement with a ‘WHERE’ clause:

MODIFY lt_my_table TRANSPORTING field1 WHERE field2 = ‘SomeCondition’.

This command updates the ‘field1’ of entries where ‘field2’ matches ‘SomeCondition’.

Deleting Data

Deleting records from an internal table is handled using the ‘DELETE’ keyword. Similar to modifying, you can delete all matching records or specific entries based on conditions.

DATA: lt_my_table TYPE TABLE OF my_structure.

” Assume lt_my_table is already populated with data

DELETE lt_my_table WHERE field1 = ‘ValueToRemove’.

 

In this case, the ‘DELETE’ statement removes entries from ‘lt_my_table’ where ‘field1’ is ‘ValueToRemove’. If you want to delete a single entry, you would typically use an index:

 

DATA: lv_index TYPE sy-tabix.

lv_index = 2. ” Index of the entry to be deleted

DELETE lt_my_table INDEX lv_index.

 

Here, ‘DELETE’ removes the entry at position 2 of ‘lt_my_table’.

 

Author : Aniket Pawar, 9373518385