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

Internal tables with/without header line : examples

Former Member
30,866

Hi everybody,

Somebody has examples of the use of the internal tables with/without header line ?

Thanks in advance

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
10,116

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.

Refer to these related threads

Regards,

Santosh

Hi everybody,

Somebody has examples of the use of the internal tables with/without header line ?

Thanks in advance

6 REPLIES 6
Read only

Former Member
0 Likes
10,116

With header line.

data : itab like standard table of vbak with header line.

data : jtab like standard table of vbak .

wa_jtab like vbak.

  • No change when seleting from the database

Select * from vbak into table itab/jtab where vbeln = 12345.

  • Loop the tables

with header line.

loop at itab. records are copied into heder line of itab.

endloop.

with out header line

loop at jtab into wa_jtab.

endloop.

  • Read statement

with header line

read table itab index 1.

witho ut header line

read table jtab into ws_jtab index 1.

Further Links

Thanaks

Mahesh

Read only

Former Member
0 Likes
10,116

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.

Reward Points If Helpful info.!

Read only

Former Member
0 Likes
10,117

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.

Refer to these related threads

Regards,

Santosh

Read only

0 Likes
10,116

How to modify an internal table - without header line. Using a row index?

Our old code uses tables with headers:

LOOP AT p_package.
  gv_tabix = sy-tabix.
  " changing header ... and more
  MODIFY p_package INDEX gv_tabix.

How to do the same for tables without headers?

Read only

Former Member
Read only

Former Member
0 Likes
10,116

Declare your table without occurs and header line option, so define the structure as a type;

TYPES: BEGIN of my_type,

field1(1),

field2(1),

END OF my_type.

DATA my_table TYPE TABLE OF my_type.

But if you dont declare HEADER LINE, you dont get HEADER LINE (seems logical) so use a work area or a pointer (FIELD SYMBOLS)

DATA wa_type TYPE my_type.

DATA wa_type2 LIKE LINE OF my_table.

LOOP AT my_table INTO wa_type.

ENDLOOP.

FIELD-SYMBOLS <type> TYPE my_type.

LOOP AT my_table ASSIGNING <type>.

ENDLOOP.