Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
mandanaveenofficial
Discoverer
0 Likes
3,600

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

Naveen_Manda1_1-1758108428636.png

2. Creating Internal Tables

Examples for creating Internal tables with type declarations and using standard table

Naveen_Manda1_2-1758108498709.png

3. Populating and processing Internal Table

Example1: Standard table  Example with Reading data from table MARA (General Article Data)

Naveen_Manda1_5-1758108565208.png

Example 2 : Appending the data to Internal table  and display.

Naveen_Manda1_6-1758108591369.png

Naveen_Manda1_7-1758108597174.png

Example 3 : Sorted table data display

aNaveen_Manda1_8-1758108617398.png

Naveen_Manda1_9-1758108631753.png

Example 4: Hashed table  data display

Naveen_Manda1_10-1758108672712.png

Naveen_Manda1_11-1758108689703.png

4. Usage of Work area and Field Symbol

Naveen_Manda1_12-1758108819570.png

Example on using work area

Naveen_Manda1_13-1758108882570.png

Result: 

Naveen_Manda1_14-1758108907551.png

Example on Field-symbol

 

Naveen_Manda1_15-1758108922544.png

Result

Naveen_Manda1_16-1758108929662.png

5. Data manipulation in Internal Table

Naveen_Manda1_17-1758109058950.png

Naveen_Manda1_18-1758109085277.png

Result 

Naveen_Manda1_19-1758109115211.png

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.

Naveen_Manda1_20-1758109428852.png

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

Naveen_Manda1_21-1758109691186.png

Naveen_Manda1_22-1758110343651.png

Naveen_Manda1_23-1758111321451.png

Naveen_Manda1_24-1758111355776.png

Naveen_Manda1_25-1758111369241.png

Naveen_Manda1_26-1758111436649.png

 

Naveen_Manda1_27-1758111491119.png

 

Naveen_Manda1_28-1758111523266.png

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
    1. Success - Type S - Displays the status of the program. ( Success message)
    2. Error - Type E - An error message appears and the program stops. 
    3. Information - Type I -  The program is executed and information message  is displayed
    4. Warning - Type W - This is used to display warning information for the user, but they don’t stop the program
    5. Exit - Type X - The program terminates and the detailed information can be found in transaction ST22
    6. 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 : 

Naveen_Manda1_29-1758111602739.png

Information Message

Syntax:      MESSAGE 'Informational message.' TYPE ‘I'.

Output:

Naveen_Manda1_30-1758111655869.png

 

Warning Message: 

Syntax: MESSAGE 'Warning message: Data inconsistent' TYPE ‘W'.

Output

Naveen_Manda1_31-1758111690871.png

 

Syntax: MESSAGE 'Warning message: Data inconsistent' TYPE 'W' DISPLAY LIKE ‘I'.

Naveen_Manda1_32-1758111702506.png

 

Error Message:

Syntax:  MESSAGE 'Error Message: An error occurred during processing.' TYPE ‘E'.

Output

Naveen_Manda1_33-1758111708996.png

Abort Message

Syntax: MESSAGE 'Abort Message:  Program terminated due to critical error.' TYPE 'A'.

Output:

Naveen_Manda1_34-1758111727927.png

Exit Message

Syntax:  MESSAGE 'Exit Message: Critical error encountered!' TYPE 'X'.

Output:

Naveen_Manda1_35-1758111752493.png

Creating Message through text messages in report

  • SE38—> In Menu bar select  GOTO —> Select text symbols —> enter text nameNaveen_Manda1_36-1758111791162.png

     

Code: Message text-001 type 'S'.

Output: 

Naveen_Manda1_37-1758111819713.png

 

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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1 Comment