Revolutionizing Data Management: A Deep Dive into Hashed Internal Tables and Beyond
Welcome back everyone, I hope you all will be fine. So basically in our last blog we were discussing about types of internal table. So let’s continue it.
Hashed Internal Tables :-
-
They are the special type of internal table which works on HASH algorithms. We need to specify the unique key while declaring the internal table.
Hashing :-
- It is a technique which directly returns the address of the record based upon the search key without using the index.
Suppose we have 5 order numbers and we have specified order number 10 as unique key, So in this case Hashing will directly map or point to the address of the order number 10.
-
They are not the index based internal table.
-
Records can be inserted.
-
Data already sorted, there is no need to use SORT statement.
-
Key operation is used to search a record, there is no index search.
-
Hashed algorithm is used to search a record.
-
Response time is faster as compared to Standard and sorted internal tables, as response time is independent of number of entries.
-
There is no concept of non unique key in hashed internal tables, If you will try to use non unique key concept, system will generate a compile time error.
****************************************************
*Start of Program
*Creating a structure.
TYPES : BEGIN OF lty_header,
order_number TYPE zar_order_number,
payment_mode TYPE zar_payment_mode,
END OF lty_header.
*Defining a hashed internal table.
DATA : lt_header TYPE HASHED TABLE OF lty_header WITH UNIQUE KEY order_number.
DATA : ls_header TYPE lty_header.
*Using insert statement.
ls_header-order_number = '1'.
ls_header-payment_mode = 'C'.
INSERT ls_header INTO TABLE lt_header.
CLEAR ls_header.
ls_header-order_number = '2'.
ls_header-payment_mode = 'C'.
INSERT ls_header INTO TABLE lt_header.
CLEAR ls_header.
ls_header-order_number = '3'.
ls_header-payment_mode = 'C'.
INSERT ls_header INTO TABLE lt_header.
CLEAR ls_header.
*Displaying the data
LOOP AT lt_header INTO ls_header.
WRITE :/ ls_header-order_number, ls_header-payment_mode.
ENDLOOP.
*End of Program
*********************************************************
Output :-
Comparison between Standard, Sorted, Hashed Internal Tables :-
1. Index :-
- Standard Internal tables are the index based internal tables.
- Sorted Internal tables are also the index based internal tables.
- Hashed internal tables are not the index based internal tables.
2. Insertion Of Records :-
- Both append and insert operations can be used to insert the records to standard internal tables.
- Only insert operation can be used to insert the records to sorted internal tables.
- Only insert operation can be used to insert the records to hashed internal tables.
3. Sorting :-
- Data is not sorted by default in standard internal table. SORT operation is used sort the data to standard internal table.
- Data is sorted by default. There is no need for SORT operation.
- SORT does not have any impact on the performance of HASHED internal table.
3. Read :-
- The record can be read from standard internal table using KEY or Index.
- They record can be read from sorted internal table using KEY or Index.
- The record can be read from hashed internal table using KEY only.
4. Search :-
- Linear of Binary Search
- Binary Search
- Hashed algorithm
5. Response Time :-
- Response time of standard internal table is less as compared to sorted and hashed internal tables as it uses linear search by default. The response time of standard internal tables depends upon the number of entries. The response time of standard internal table can be improved by using binary search.
- Response time of sorted internal table is fast as compared to standard internal table as it uses binary search.
- Response time of hashed internal table is fast as compared to standard and sorted internal tables. The response time of hashed internal tables does not depend upon the number of entries. It is well suited for tables, where a table has huge number of records and we want to search based upon unique key.
Some Important Questions :-
- Which of the internal tables are indexed based internal tables ?
Ans :- Standard, Sorted
- Is standard internal table only uses linear search ?
Ans :- By default, standard internal table uses linear search, We can use binary search also.
- Can we use append to insert a record to sorted internal table ?
Ans :- No, append is never preferred , as it will result in to runtime error, if we insert a record that is not in sorted order.
- Which internal table has highest performance when there is large amount of data and search is based upon unique key ?
Ans :- Hash internal Table
- What is the difference between append and insert ?
Ans :- Append inserts the record at the last of the internal whereas Insert inserts the record at anywhere in the internal table.
Internal Table With Header Line :-
- In case of internal table with header line, there is an implicit (internal ) work area.
- The name of the work area is same as that of internal table.
- To clearly identify the internal table, use brackets after the internal table name (<itab>[]).
- CLEAR <itab>[] - Clear the contents of internal table.
Important Points :-
- In case of internal table with header line, CLEAR <itab> clears the work area, not the internal table. If you want to clear the internal table use brackets after the internal table name.
Internal Table Without Header Line :-
- We can avoid the confusion of internal table with header line by using the concept of internal table without header line.
- In case of internal table without header line, there is an explicit ( external ) work area.
- We declare an explicit work area.
- The name of the internal table is different from as that of work area.
- CLEAR <itab> - Clear the contents of internal table.
Practical Implementation Of Internal Table With Header Line :-
****************************************************
*Start of Program
*Creating a structure.
TYPES : BEGIN OF lty_header,
order_number TYPE zar_order_number,
payment_mode TYPE zar_payment_mode,
END OF lty_header.
*Defining a internal table with header line.
DATA : lt_header TYPE table of lty_header WITH HEADER LINE.
*Appending data.
lt_header-order_number = '1'.
lt_header-payment_mode = 'C'.
append lt_header.
CLEAR lt_header.
lt_header-order_number = '2'.
lt_header-payment_mode = 'C'.
append lt_header.
CLEAR lt_header.
lt_header-order_number = '3'.
lt_header-payment_mode = 'C'.
append lt_header.
CLEAR lt_header.
*Displaying the data
LOOP AT lt_header.
WRITE :/ lt_header-order_number, lt_header-payment_mode.
ENDLOOP.
*End of Program
*********************************************************
Output :-
You can see there are alot of confusion with header line concept.
In debugger mode, you will be able to understand it more clearly.
So, that’s enough for today.
We will continue with Selection Screen in the next blog.
Thanx alot for being a part of this wonderful journey.
Comments
Post a Comment