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

Itab with/without header line

Former Member
0 Likes
2,982

Hi,

when do you need to create an internal table with header line and with out a header line?

Hi,

when do you need to create an internal table with header line and with out a header line?

10 REPLIES 10
Read only

Former Member
0 Likes
1,790

HI,

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.

Internal table with header line

you can use anywhere except obkect oriented concept.

Internal table without header line :

You should use in Object oriented concept..

Always try to use without header line,performance point of view it is best..

Example :

Without header line.

  • Structure

types : begin of ty_itab ,

matnr type mara-matnr,

end of ty_itab.

  • Internal table

data i_itab type standard table of ty_itab .

  • Work area

data wa_itab like line of i_itab

With header line

data : begin of i_itab occurs 0,

matnr like mara-matnr,

end of i_itab

itab with header lines are obsolete, anyway it will work but not recommended. instead use work area or more effiecient is field symbols. so donot use itab with header line.

i will explain use of itab w/o header line.

Data: itab1 type standard table of mara with header line occurs 0,

itab2 type standard table of mara,

wa_itab2 type mara.

loop at itab1.

"This will work fine.

endloop.

loop at itab2.

"This will give erro that itabd does not hav workarea

endloop.

"so write

loop at itab2 into wa_itab2.

"This will work

endloop.

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

Regards

Sudheer

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,790

Hi,

Only ABAP Objects does not allow you to create a table with headerline, so with ABAP objects you need to always create Workarea.

Every where else you can use Tables With Headerline.

But the concept is obsolete as there is confusion with CLEAR statement.

Example:


DATA: itab type table SPFLI with header line.

CLEAR itab. " Clar the header line but keeps the table.

 " We need to do
CLEAR itab[]. " to clear the table.

Regards,

Sesh

Read only

Former Member
0 Likes
1,790

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.

Internal table with header line

you can use anywhere except obkect oriented concept.

Internal table without header line :

You should use in Object oriented concept..

Always try to use without header line,performance point of view it is best..

Example :

Without header line.

  • Structure

types : begin of ty_itab ,

matnr type mara-matnr,

end of ty_itab.

  • Internal table

data i_itab type standard table of ty_itab .

  • Work area

data wa_itab like line of i_itab

With header line

data : begin of i_itab occurs 0,

matnr like mara-matnr,

end of i_itab

itab with header lines are obsolete, anyway it will work but not recommended. instead use work area or more effiecient is field symbols. so donot use itab with header line.

i will explain use of itab w/o header line.

Data: itab1 type standard table of mara with header line occurs 0,

itab2 type standard table of mara,

wa_itab2 type mara.

loop at itab1.

"This will work fine.

endloop.

loop at itab2.

"This will give erro that itabd does not hav workarea

endloop.

"so write

loop at itab2 into wa_itab2.

"This will work

endloop.

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

regards,

srinivas

<b>*reward for useful answers*</b>

Read only

Former Member
0 Likes
1,790

If you want to improve your coding never ever use an internal table with a header line again, instead use the avauilable table types and field-symbols for altering data in an itab, as this is more transparent and a lot faster.

Kind regards, Rob Dielemans

Read only

Former Member
0 Likes
1,790

Never user header line.

Always create a line type(i.e. work area) of ur internal table and use it when u want to perform some calculation on records in internal table.

It improves the performance.

Read only

Former Member
0 Likes
1,790

Hi Sourav,

Go through this hope u can understand.

With header line means you can keep multiple records in an internal table

without header line it acts as a structure which hold a single record

1) 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.

Reward points if helpful.

Thanks

Naveen khan

Read only

Former Member
0 Likes
1,790

Hi Saurav,

When you create new Internal table that time header line means work area is automatically create. But when you difine any internal table as like another table that time you have to add statement with header line.

For Ex.

DATA : BEGIN OF ITAB OCCURS 0 ,

MATNR LIKE MARA-MATNR,

.

.

.

END OF ITAB.

In this case you will automatically get Header line.

But when you define like this,

DATA : ITAB LIKE MARA OCCURS 0 WITH HEADER LINE.

in this case you have to define header line.

That means when you use LIKE that time you have to use WITH HEADER LINE.

Pradip Pawar .

Rewards points if answer is valuable.

Read only

Former Member
0 Likes
1,790

HI

you can do you work with both itabs with and without header line...but it is recommended that you use without header line and create a seperate work area for performance tuning issues.

no such hard and fast rules....you can do ur task either way

Thanks

vivekanand

Read only

Former Member
0 Likes
1,790

Hi Sourav,

There is no difference in using table with header line and table without header line.

in case of header line , automatically there is work area with the same name as that of table.

but in case of without header line we need to specify explicit work area.

These days we are not using with header line as it is already obselete.

Reward points if found useful.

Thanks,

Gaurav Mittal

Read only

Former Member
0 Likes
1,790

Using header line is good for understanding at the begining but in real senerio it better to work with work area it will increase the performance as well runtime efficency of the program.

Regards,

Mehfuze