Friday, July 17, 2015

Internal Table Basics

Internal table is a data object in ABAP that exists only at run time of a program. It means when the program execution is complete then the internal table will be lost. We use internal table to store database table data after fetching it by a select query. The ABAP run-time system dynamically manages the internal table’s memory. It means we developer do not need to work on memory management of internal table.

Internal table has three parts – rows, columns & work area.
1.       Rows are the line type of internal table. It is a structure which contains several fields. Those fields are of data elements. We need to declare the structure locally or globally to declare the internal table.
2.       Columns are the fields of internal table. Those fields are of different data elements declared by locally or globally.
3.       The most important part of an internal table is its work area. Work area is basically the line type of an internal table. It means it has the same structure of the rows of internal table. Work area contains the same fields of same type of the rows. It is of two types – implicit & explicit work area.
A.      When we declare an internal table with header line then a work area is automatically created with the same name of the table. This work area is called implicit work area which is actually the header line. There is no need to declare work area separately. This work area / header line contains the same table as of the internal table.

Example –
TYPES: BEGIN OF ty_mat,
         matnr TYPE mara-matnr,
         werks TYPE marc-werks,
         lgort TYPE mard-lgort,
       END OF ty_mat.

DATA: it_mat TYPE STANDARD TABLE OF ty_mat WITH 
NON-UNIQUE KEY
      matnr WITH HEADER LINE.

Here we have declared a local structure ty_mat. This is the line type / row of the internal table. It means the table will contain rows which has three fields (matnr, werks & lgort). We declare the internal table it_mat with this local structure. We also can declare with global structure.

DATA: it_qinfo TYPE TABLE OF slis_qinfo_alv WITH HEADER LINE
      WITH NON-UNIQUE KEY type.

Here slis_qinfo_alv is a structure which has been declared globally in data dictionary. We can declare the internal table directly with the table type also.

DATA: it_qinfo TYPE slis_t_add_fieldcat WITH HEADER LINE.

Here slis_t_add_fieldcat is a table type declared in data dictionary.

Header line concept:

MATNR                 WERKS                 LGORT



 The name of this work area / header line is IT_MAT.

When we create the internal table then it is like following:

MATNR                 WERKS                LGORT















It also contains the same name IT_MAT but it is mentioned IT_MAT[ ] in the program.

B.      If we declare an internal table without header line then we need to declare its work area seperately. Since we are declaring the work area explicitly it is called explicit work area. This work area contains the different name from the internal table.

Example –
TYPES: BEGIN OF ty_mat,
         matnr TYPE mara-matnr,
         werks TYPE marc-werks,
         lgort TYPE mard-lgort,
       END OF ty_mat.

DATA: it_mat TYPE STANDARD TABLE OF ty_mat,
      wa_mat TYPE ty_mat.

Similarly we can declare internal table with globally declared structure or table type also.
DATA: it_qinfo TYPE TABLE OF slis_qinfo_alv WITH NON-UNIQUE KEY type.
DATA: it_qinfo TYPE slis_t_qinfo_alv.

Work area concept:

MATNR                 WERKS                 LGORT



 The name of this work area is WA_MAT.

When we create the internal table then it is like following:

MATNR                 WERKS                LGORT















The table contains the name IT_MAT.

In today’s programming header line is not used in internal table. It is now obsolete. There are two main reasons for that.
1.       The automatically generated header line / implicit work area has the same name as of internal table. That’s why it loses the readability of program.
2.       When we use nested data objects (internal table has components of structure which is another internal table) then header line is not allowed. In object oriented programming header line is not allowed.

To declare an internal table there is three basic specifications. They are 1. Row type, 2. Key & 3. Types of internal table. Internal table is of three types – standard table, sorted table & hashed table. Standard & sorted tables are called index table because we can access its records by its index. Index is nothing but a row number of the internal table.

1.       Standard table is an index table which has non-unique key. It can be accessed by index or key also. If we want to access by key then the key must be defined otherwise default key would be considered. The declaration is as follows:

DATA: it_mat TYPE STANDARD TABLE OF ty_mat WITH NON-UNIQUE KEY matnr.
OR
DATA: it_mat TYPE TABLE OF ty_mat WITH NON-UNIQUE KEY matnr.

If we don’t mention “Standard table of” clause then by default the system takes it as a standard internal table. We can enter data into a standard internal table by using the APPEND statement. Append always enters data at the last row of the table.

APPEND wa_mat TO it_mat.

2.       Sorted table is another kind of index table which has unique / non unique key. It also can be accessed via index or key. For sorted table the key must be specified. The declaration is as follows:

DATA: it_mat TYPE SORTED TABLE OF ty_mat WITH UNIQUE KEY matnr,
      it_mat TYPE SORTED TABLE OF ty_mat WITH NON-UNIQUE KEY matnr.

Unique key means the MATNR (material no) will must be unique. If same material number is inserted then a run time error will happen. However we can declare the sorted table with non unique key also. In this case same material number can be entered but it will be sorted after entering the number. Here the sorted table behaves similar to sorted standard table. We use INSERT statement to enter any records to the sorted table.

INSERT wa_mat INTO it_mat.

3.       Hashed table is not an index table. It follows the hash algorithm. Here the declaration of key is must and also the key must be unique. Hence no duplicate entry will be in the hashed table. We can access records only by the key.

DATA: it_mat TYPE HASHED TABLE OF ty_mat WITH UNIQUE KEY matnr.

Similar to sorted tables data can be inserted here by INSERT statement. Hashed tables are used when the internal table contains huge volume of data.

INSERT wa_mat INTO TABLE it_mat.

Table kind
Index Tables
Hashed Tables
Standard Table
Sorted Table
Index Access
Yes
Yes
No
Key Access
Yes
Yes
Yes
Key Uniqueness
Non unique
Unique/Non unique
Unique
Usage
Index access
Key access
Only key access


33 comments:

Anonymous said...

Very interesing. Keep up with the excellent work.

anmol gupta said...

good work sir

sanju said...

Great Job!!!

sandeep Gunda said...

very nice

Anonymous said...

Expecting some new sides of SAP ABAP from you. This blog is right now saturated. Please gives us more fundamental docs.

Suraj Kumar Acharjya said...

Excellent Work ... Please keep updating. Thanks

Mahesh Ram said...

Good ezplantion about internal tables and work areas. Thanks for sharing about standard tables, sorted tables and hashed tables. Can we use this types in real time? SAP ABAP ONLINE TRAINING

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

Shalini said...


Hi, This is shalini from Chennai learned SAP Training in Chennai from mr.karthick. The training really was good and i got selected in leading mnc company as SAP Consultant.

You can contact 8122241286 for Best SAP Training in Chennai or reach www.thecreatingexperts.com

bharat said...

I like this blog i clear my concept

Rupesh Kandru said...

really nice explanation
but what are the search techniques those tables

SANDIP ROY said...

READ TABLE with key & BINARY SEARCH for all kind of tables.

sushma said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trianer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

syed khutubuddin ahmed said...

Great work sir. I really liked your blog. May god bless you with lots and lots of Success with joy in your life.

Shruti Ramalingam said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

Shruti Ramalingam said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

sanayamohit said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

Rajendra G said...

the way you explained is very nice

sushma said...

Best SAP Success Factor Training in Chennai

http://thecreatingexperts.com/sap-training-in-chennai/
http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
http://thecreatingexperts.com/sap-mm-training-in-chennai/
http://thecreatingexperts.com/sap-fico-training-in-chennai/

Sasi Sivakumar said...

Best SAP Success Factor Training in Chennai

http://thecreatingexperts.com/sap-training-in-chennai/
http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
http://thecreatingexperts.com/sap-mm-training-in-chennai/
http://thecreatingexperts.com/sap-fico-training-in-chennai/

suganya said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

suganya said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

Priyasekar said...


SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

Unknown said...

Best SAP Success Factors Real Time Hands on Training In Chennai

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

ramana said...

good blog,thank you for sharing information sap abap online training in hyderabad

sushma said...

Hey informative blog...THE CREATING EXPERTS is one of the leading trainers in SAP abap and basis Real Time Hands on Training in Chennai…


http://thecreatingexperts.com/sap-abap-training-in-chennai/


CONTACT:8122241286

http://thecreatingexperts.com/sap-basis-training-in-chennai/

ramana said...

excellent blog,thank you for sharing a valuable information to us online abap training in hyderabad

sushma said...

Informative Blog...For a long time I was craving for a career growth in programming and then I came to know that THE CREATING EXPERTS is the one who provide training with hands on training and real time scenarios

http://thecreatingexperts.com/sap-abap-training-in-chennai/

contact 8122241286

Priyasekar said...

Thanks for your info...Here THE CREATING EXPERTS provide hands on training with real time scenarios

http://thecreatingexperts.com/sap-abap-training-in-chennai/

contact +91-08122241286

sanayamohit said...

Hi, I learned SAP Training in Chennai from THE CREATING EXPERTS. The training was good and i got selected in leading MNC company as SAP Consultant.

contact 8122241286

www.thecreatingexperts.com

ragu varan said...

Best SAP HANA Training in Chennai by leading HANA Consultant.
Reach at 9003085882 or

Anonymous said...

Keep up the good work!!!

gilledashivani said...

Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD