Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Performance difference between internal table with and without header line

former_member632991
Active Contributor
0 Kudos
1,181

Hi,

What are the performance difference between the internal table declared with and without header line?

Why should internal tables be declared without header line?

Regards,

Sonika Ahuja

11 REPLIES 11
Read only

Former Member
0 Kudos
502

hi SOnika,

When you create an internal table object you can also declare a header line with the same name. You can use the header line as a work area when you process the internal table. The ABAP statements that you use with internal tables have short forms that you can use if your internal table has a header line. These statements automatically assume the header line as an implicit work area. The following table shows the statements that you must use for internal tables without a header line, and the equivalent statements that you can use for internal tables with a header line:

Operations without header line

Operations with header line

Operations for all Table Types

INSERT <wa> INTO TABLE <itab>.

INSERT TABLE ITAB.

COLLECT <wa> INTO <itab>.

COLLECT <itab>.

READ TABLE <itab> ... INTO <wa>.

READ TABLE <itab> ...

MODIFY TABLE <itab> FROM <wa> ...

MODIFY TABLE <itab> ...

MODIFY <itab> FROM <wa> ...WHERE ...

MODIFY <itab> ... WHERE ...

DELETE TABLE <itab> FROM <wa>.

DELETE TABLE <itab>.

LOOP AT ITAB INTO <wa> ...

LOOP AT ITAB ...

Operations for Index Tables

APPEND <wa> TO <itab>.

APPEND <itab>.

INSERT <wa> INTO <itab> ...

INSERT <itab> ...

MODIFY <itab> FROM <wa> ...

MODIFY <itab> ...

Using the header line as a work area means that you can use shorter statements; however, they are not necessarily easier to understand, since you cannot immediately recognize the origin and target of the assignment. Furthermore, the fact that the table and its header line have the same name can cause confusion in operations with entire internal tables. To avoid confusion, you should use internal tables with differently-named work areas.

The following example shows two programs with the same function. One uses a header line, the other does not.

With header line:

TYPES: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

DATA ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1

WITH HEADER LINE.

DO 4 TIMES.

ITAB-COL1 = SY-INDEX.

ITAB-COL2 = SY-INDEX ** 2.

INSERT TABLE ITAB.

ENDDO.

ITAB-COL1 = 2.

READ TABLE ITAB FROM ITAB.

ITAB-COL2 = 100.

MODIFY TABLE ITAB.

ITAB-COL1 = 4.

DELETE TABLE ITAB.

LOOP AT ITAB.

WRITE: / ITAB-COL1, ITAB-COL2.

ENDLOOP.

Without header line:

TYPES: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

DATA: ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1,

WA LIKE LINE OF ITAB.

DO 4 TIMES.

WA-COL1 = SY-INDEX.

WA-COL2 = SY-INDEX ** 2.

INSERT WA INTO TABLE ITAB.

ENDDO.

WA-COL1 = 2.

READ TABLE ITAB FROM WA INTO WA.

WA-COL2 = 100.

MODIFY TABLE ITAB FROM WA.

WA-COL1 = 4.

DELETE TABLE ITAB FROM WA.

LOOP AT ITAB INTO WA.

WRITE: / WA-COL1, WA-COL2.

ENDLOOP.

The list, in both cases, appears as follows:

1 1

2 100

3 9

The statements in the program that does not use a header line are easier to understand. As a further measure, you could have a further work area just to specify the key of the internal table, but to which no other values from the table are assigned.

Regards,

Santosh

Read only

vidya_gugnani
Product and Topic Expert
Product and Topic Expert
502

Hi Sonika,

If we don't want to use any explicit work area then its better to go for an internal table with header line.

When you do not want an implicit work area and are creating one of your own,it is advisable not to use header lines,moroever with 710 releases ABAP 3.0,this will give you a syntax error as this is not supported in ABAP Object Oriented Programming.

This results in performance problems as memory is explicitly reserved for the header lines.

While adding or retrieving records to / from internal table we have to keep the record temporarily.

The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.

Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.

e.g.

data: begin of itab occurs 10,

ab type c,

cd type i,

end of itab. " this table will have the header line.

data: wa_itab like itab. " explicit work area for itab

data: itab1 like itab occurs 10. " table is without header line.

The header line is a field string with the same structure as a row of the body, but it can only hold a single row.

It is a buffer used to hold each record before it is added or each record as it is retrieved from the internal table. It is the default work area for the internal table.

See info at this link:

http://www.sap-img.com/abap/difference-between-work-area-and-header-line.htm

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/abap+runtime&;

Read only

Former Member
0 Kudos
502

Hi Sonika,

Please refer the links,

Regards,

Hema.

    • Reward points if it is useful.

Read only

anversha_s
Active Contributor
0 Kudos
502

hi,

* Table declaration (old method)
"old method
DATA: BEGIN OF tab_ekpo OCCURS 0,             "itab with header line
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
 END OF tab_ekpo.

"alwys use like below.

*Table declaration (new method)     "USE THIS WAY!!!
TYPES: BEGIN OF t_ekpo,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
 END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,      "itab
      wa_ekpo TYPE t_ekpo.                    "work area (header line)

Regards

Anver

Read only

Former Member
0 Kudos
502

Hi,

Main difference is the usuage of the memory allocated for internal table.

Internal table with headerline will allocates the memory as 8k,16k,32k,64k,128k,256k,512k,1024k,2048k.....etc.

Suppose one internal table has the data of capacity 1026k then system allocates 2048k memory to internal table. Half the amount of memory is not useful.

Internal table without headerline memory consumption is less compare to internal table with header line.

In ABAP WAS 6.20 after onwards internal table without headerline is obsolete.

Internal table without headerline requires an explicit workarea.

Regards

Bhupal Reddy

Read only

Former Member
0 Kudos
502

Hi

The difference between

whih header line and with out heater line of internal table.

ex:-

a) Data : itab like mara occurs 0 with header line.

b) Data: itab like mara occurs 0.

-While adding or retrieving records to / from internal table we have to keep the record temporarily.

-The area where this record is kept is called as work area for the internal table.

-The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.

-Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.

a) Data : itab like mara occurs 0 with header line.

table is with header line

b) Data: itab like mara occurs 0.

table is without header line

2)work area / field string and internal table

which one is prefarable for good performance any why ?

-The header line is a field string with the same structure as a row of the body, but it can only hold a single row , whereas internal table can have more than one record.

In short u can define a workarea of an internal table which means that area must have the same structure as that of internal table and can have one record only.

Example code:

data: begin of itab occurs 10,

ab type c,

cd type i,

end of itab. " this table will have the header line.

data: wa_itab like itab. " explicit work area for itab

data: itab1 like itab occurs 10. " table is without header line.

Hope this helps

-charitha

Read only

Former Member
0 Kudos
502

Hi sonika,

1. For most practical purposes, (except for class based program)

it does not matter whether we use header line or not .

2. It only matters performance wise when

the record numbers are very high.

For few thousands to 1 lac record, it does not matter much.

regards,

amit m.

Read only

Former Member
0 Kudos
502

Hi Sonika ,

The basic reason why internal table must be declared without a header line is that it is not supported in ABAP Objects .

One comman example can be that when we have a header then the statement used determines whether we are refering to the table or the work area , so in order to avoid such confusion it it better to user a work area.

If we look at pure performance , when the amount of data is less workareas are better , but as volume increases this diffrence decreases at a perticular point table with header line are better and then with very large volume of data tables with work area are better.

Here is a code to illustrate the same.

types : begin of ty_1 ,
          num type i ,
        end of ty_1.
data : begin of it_1 occurs 0 ,
         num type i ,
       end of it_1.
data : r1_b type i        ,
       r1_e type i ,
       r1_d type i .

.
data : it_2 type table of ty_1 ,
       wa_2 type ty_1.

get run time field r1_b.

do 100000000  times.  " Change the values starting from 10 and see the output
it_1-num = sy-index.
append it_1.
clear it_1.

enddo.
loop at it_1.
*write it_1-num.
endloop.

get run time field r1_e.

r1_d = r1_e - r1_b.
write:/ 'run time loop '  , r1_d.
clear : r1_b , r1_e ,r1_d.

get run time field r1_b.
do 100000000  times. " Change the values starting from 10 and see the output
  wa_2-num = sy-index.
  append wa_2 to it_2.
  clear wa_2.
enddo.

loop at it_2 into wa_2.
*write wa_2-num.
endloop.
get run time field r1_e.
r1_d = r1_e - r1_b.
write:/ 'run time workarea'  , r1_d.

so observing the output we can safely say that usiing table with workarea is always better.

Regards

Arun

Read only

anversha_s
Active Contributor
0 Kudos
502

hi,

Adding to the above.

By using this, you can store the records in the Internal table,

If you give Occues 0 then we are giving ful space(8kb) to Internal table,

if you give occurs 5, then you are assiging less space,

this is very usefull for large amount of data,

if the total no of records in the internal table execced the 8kb,

then the system automatically assign 8kb space again,

so if you are dealing with small amount of data in the internal table,

then make use of this occurs N, so you won't get any memero related problems

Regards

Anver

Read only

former_member632991
Active Contributor
0 Kudos
502

Hi,

Please don't explain me about the internal tables with header line or without and the oiperations.

I exactly want to know why the performance in better when we use the interna table without header line. When we declare internal table without header line, then exlicitly we have to declare a WA , it means for any operation first update the WA and then that internal table from WA. Then how it is having better performance than with header line?

Regards,

Sonika

Read only

former_member632991
Active Contributor
0 Kudos
502

.