- SAP ABAP
- What is SAP ABAP
- SAP ABAP Data Dictionary and Domain
- SAP ABAP Data Element
- SAP ABAP Database Table
- SAP ABAP Database tables and views
- SAP ABAP Foreign Key
- SAP ABAP Indexes
- SAP ABAP Structure
- SAP ABAP Package
- SAP ABAP Adding Fields to SAP Standard Table
- SAP ABAP Internal Table and Database Table
- SAP ABAP Select Option and Parameter
- SAP ABAP Types of Internal Table
- SAP ABAP ways of Declaring Internal Tables
- SAP ABAP Mastering Initialization Technique
- SAP ABAP Operations on Internal Table
- SAP ABAP Record Retrieval
- SAP ABAP Insert, Modify and Delete data in the Internal table by using Keywords
- SAP ABAP Sorting and Removing Adjacent Duplicates
- SAP ABAP Seamless Data Transfer Between Internal Tables
- SAP ABAP Search Help Types
- SAP ABAP Lock Objects and Types
- SAP ABAP Buffering and Its Types
- SAP ABAP TMG
- SAP ABAP Table Types
- SAP ABAP Views
- SAP ABAP Control Break Statement
- SAP ABAP COMMIT and ROLLBACK
- SAP ABAP Joins
- SAP For All Entries
- SAP ABAP Procedure to Fill Final Internal Table
- SAP ABAP Modularization
- SAP ABAP Function Group and Function Module
- SAP ABAP SELECT Options
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