Working with internal Tables
Below topics we are going to discuss in detail
1.Types of Internal Tables
2.Creating Internal Tables
3.Populating and Processing Internal Tables
4.Usage of work area and Field-symbol
5.Data manipulation in Internal table
6.Parallel Cursor usage
7.Control Break Statements
8.Messages
1. Types of Internal Tables
In SAP ABAP (Advanced Business Application Programming), Internal tables are used to store temporary data during program execution.
There are three main types of internal tables in SAP:
- Standard Internal Table
- Sorted Internal Table
- Hashed Internal Table
Standard Internal Table
This is default internal table type.
In Standard internal table, Table entries are stored in the order they are inserted.
- Standard internal table are not sorted automatically. We have to use the SORT statement for sorting the table entries based on keys.
- Standard internal table follows Linear search process for searching the records
- Here passing of data from work area to internal table is through APPEND keyword.
- Standard internal table is not recommended for large datasets
- Standard internal table accepts duplicate entries unless explicitly defined with a unique key.
- Standard internal table is accessed by using index or key
Usage: Standard internal table is recommended only when sequence of fields are mattered or dealing with small datasets.
Example : DATA: lt_standard TYPE STANDARD TABLE OF mara.
Sorted Internal Table
Sorted internal table entries are automatically sorted based on a defined key.
- Sorted internal table follows binary search process for searching of records
- Here passing of data from work area to internal table is through INSERT keyword.
- Can enforce unique keys or allow duplicates depending on declaration
- Here we must specify at least one field as unique or non-unique
- Cannot manually sort or insert at a specific position.
- Sorted internal table is accessed by using index or key
Usage: Sorted internal table is recommended for reading the entries based on keys
Example: DATA: lt_sorted TYPE SORTED TABLE OF mara WITH UNIQUE KEY matnr.
Hashed Internal Table
Hashed internal table uses a hashed algorithm for key-based access.
- Hashed internal table follows Hashed Algorithm for searching of single record
- Here passing of data from work area to internal table is through COLLECT keyword.
- Fastest access for reading single entries using keys.
- It does not accept duplicate records.
- Only allows unique keys.
- Hashed internal table is accessed by using key only
Usage: Hashed internal table is recommended for reading single entry from table by using key
Example: DATA: lt_hashed TYPE HASHED TABLE OF mara WITH UNIQUE KEY matnr.
Decision Framework of Standard/ Sorted / Hashed Internal Tables
2. Creating Internal Tables
Examples for creating Internal tables with type declarations and using standard table
3. Populating and processing Internal Table
Example1: Standard table Example with Reading data from table MARA (General Article Data)
Example 2 : Appending the data to Internal table and display.
Example 3 : Sorted table data display
a
Example 4: Hashed table data display
4. Usage of Work area and Field Symbol
Example on using work area
Result:
Example on Field-symbol
Result
5. Data manipulation in Internal Table
Result
6.Parallel Cursor
Parallel cursor is a performance optimization technique used primarily to enhance the efficiency of programs involving nested loops, especially when dealing with large internal tables.
Improve the performance of program.
Decreases the CPU and memory consumption associated with extensive loop iterations.
7.Control Break Statements
Control break statements are events inside the loop statement.
There are 5 control break statements in ABAP.
They are used within loop.(Except ON CHANGE OF which can be used outside the loop as well)
AT FIRST – ENDAT
AT NEW – ENDAT
AT END OF – ENDAT
AT LAST – ENDAT
ON CHANGE OF
AT FIRST: Will trigger at the first run of the loop.
AT LAST: Will trigger at the last run of the loop.
The below 3 events are normally used when the table is sorted.
AT END OF : When we use At end for a field, it will trigger whenever there is any change in any of the fields from the left to that of the particular field. The trigger point will be the at the last occurrence of the same value for the field.
AT NEW: When we use At new for a field, it will trigger whenever there is any change in any of the fields from the left to that of the particular field.The trigger point will be the at the first occurrence of the new value for the field.
ON CHANGE OF: On change of it triggers only when there is any change in the particular field.
On change of can be used outside the loop too
Example code on Control Break Statements
8. Messages
- In classical ABAP reports, messages are used to communicate information, warnings, errors, or success statuses to the user.
- These messages are typically displayed on the screen or in the status bar, and their behaviour depends on the message type.
- Message Types in ABAP
- Success – Type S – Displays the status of the program. ( Success message)
- Error – Type E – An error message appears and the program stops.
- Information – Type I – The program is executed and information message is displayed
- Warning – Type W – This is used to display warning information for the user, but they don’t stop the program
- Exit – Type X – The program terminates and the detailed information can be found in transaction ST22
- Abort – Type A – The message appears in a dialog box and the program terminates.
Success Message:
Syntax : MESSAGE ‘Success message: Operation successful!' TYPE ’S'.
Output :
Information Message
Syntax: MESSAGE ‘Informational message.' TYPE ‘I'.
Output:
Warning Message:
Syntax: MESSAGE ‘Warning message: Data inconsistent' TYPE ‘W'.
Output
Syntax: MESSAGE ‘Warning message: Data inconsistent' TYPE ‘W' DISPLAY LIKE ‘I'.
Error Message:
Syntax: MESSAGE ‘Error Message: An error occurred during processing.' TYPE ‘E'.
Output
Abort Message
Syntax: MESSAGE ‘Abort Message: Program terminated due to critical error.' TYPE ‘A'.
Output:
Exit Message
Syntax: MESSAGE ‘Exit Message: Critical error encountered!' TYPE ‘X'.
Output:
Creating Message through text messages in report
- SE38—> In Menu bar select GOTO —> Select text symbols —> enter text name
Code: Message text-001 type ‘S'.
Output:
Thanks!!
Finally we covered working with internal tables, creating and populating data in report , work area and field symbol usage , Parallel cursor usage, Control break statements, Messages



