‎2007 Jun 09 10:04 PM
what is the difference between using a internal table with header line and without header line? where we geneally use these two cases?
‎2007 Jun 09 11:01 PM
hi,
<b>INTERNAL TABLE</b>
Internal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays. Since they are dynamic data objects, they save the programmer the task of dynamic memory management in his or her programs.
<b>
If we r working with ABAP OBJECT(oops), it doesn't support internal table creation with headerline
if we can create internal table with header line then internal table created with explict work area. header line having the same name of internal table.</b>
<b>if we can create internal table without header line then internal table created with out explict work area. for proecssing internal table we must create workarea.
or by using fieldsymbols to processing.</b>
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.
Example
The following example shows two programs with the same function. One uses a header line, the other does not.
<b>With header line:</b>
<b>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.</b>
<u><b>Without header line:</b></u>
<b>
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.</b>
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.
<u><b>follow this link for more information.</b></u>
‎2007 Jun 09 10:31 PM
Internal table with header line should not use OO ALV and Internal taable events
if you use Internal table with header line ,then it will be performance issue
See the example both header and header line and do compare both programs .
Internal table with header line
here i am using get time field command ,so use both program and see comparision time
report zxyz.
Internal table with header line.
DATA:BEGIN OF itab OCCURS 0,
lifnr LIKE lfa1-lifnr,
name1 LIKE lfa1-name1,
END OF itab.
data : f1 type i,
f2 type i,
f3 type i.
start-of-selection.
get run time field f1.
SELECT lifnr name1 FROM lfa1 INTO TABLE itab up to 200 rows.
loop at itab.
endloop.
get run time field f2.
f3 = f2 - f1 .
write 😕 'Time taken by query in Micro seconds', f3.
Internal table without header line
report zxyz1.
Internal table without header line.
types : begin of ty_itab ,
lifnr LIKE lfa1-lifnr,
name1 LIKE lfa1-name1,
end of ty_itab.
data itab type standard table of ty_itab.
data wa_itab like line of itab.
data : f1 type i,
f2 type i,
f3 type i.
start-of-selection.
get run time field f1.
SELECT lifnr name1 FROM lfa1 INTO TABLE itab up to 200 rows.
loop at itab into wa_itab.
endloop.
get run time field f2.
f3 = f2 - f1 .
write 😕 'Time taken by query in Micro seconds', f3.
Reward Points if it is helpful
Thanks
Seshu
‎2007 Jun 09 11:01 PM
hi,
<b>INTERNAL TABLE</b>
Internal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays. Since they are dynamic data objects, they save the programmer the task of dynamic memory management in his or her programs.
<b>
If we r working with ABAP OBJECT(oops), it doesn't support internal table creation with headerline
if we can create internal table with header line then internal table created with explict work area. header line having the same name of internal table.</b>
<b>if we can create internal table without header line then internal table created with out explict work area. for proecssing internal table we must create workarea.
or by using fieldsymbols to processing.</b>
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.
Example
The following example shows two programs with the same function. One uses a header line, the other does not.
<b>With header line:</b>
<b>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.</b>
<u><b>Without header line:</b></u>
<b>
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.</b>
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.
<u><b>follow this link for more information.</b></u>