2006 Dec 01 1:38 PM
Difference between the internal table with Header Line and without Header Line....and how does it is declare & Created.
Difference between the internal table with Header Line and without Header Line....and how does it is declare & Created.
2006 Dec 01 1:41 PM
hi
when and internal table without header is used, the operations of that internal table should be performed from/to a workarea or fieldsymbol instead of a header line.
for example: (int-table with header line)
data: begin of itab occurs 0,
var1 type i,
var2 type char,
var3 type i,
end of itab.
example: (internal table without header line)
types: begin of type1,
var1 type i,
var2 type char,
var3 type i,
end of type1.
data: itab type table of type1,
workarea type type1.
thanks
pavan
2006 Dec 01 1:42 PM
HI,
In simple terms when you declare an itab with hedaer line, it can hold more than one record in the table during runtime.
Without the header line, the itab is just a header, that is, it can hold only one record at any point of time.
I hope itz clear...
Regards,
kumar
2006 Dec 01 1:42 PM
Hi Bhaskar,
Declaration of Internal tables with and w/o Header lines.
<b>Internal table with HEADER LINE</b>
Data:
Begin of Itab OCCURS 0 WITH HEADER LINE,
matnr type mara-matnr,
End of Itab.
<b>Internal table w/o HEADER LINE</b>
Data:
Begin of Itab OCCURS 0,
matnr type mara-matnr,
End of Itab.
1) By default OCCURS clause creates internal tables w/o header lines.
2)Internal table with header lines does not need a work area when performing any operation on Internal tables,
Otherwise it needs an explicit work area for performing operations on Internal tables.
3) You can also create internal tables on the base of TYPES.
TYPES:
BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
END OF TY_MARA.
<b>Internal table with HEADER LINE</b>
DATA IT_MARA TABLE TYPE STANDARD TABLE OF TY_MARA.
<b>Internal table w/o HEADER LINE</b>
DATA IT_MARA TABLE TYPE STANDARD TABLE OF TY_MARA WITH HEADER LINE.
Thanks,
Vinay
2006 Dec 01 1:43 PM
hi,
types : begin of t_mara,
matnr like mara-matnr,
ersda like mara-ersda,
end of t_mara.
data: it_mara1 type table of t_mara with header line,
it_mara2 type table of t_mara.In the above code, it_mara1 is an internal table with header line and it_mara2 is an internal table without header line.
Regards,
Sailaja.
2006 Dec 01 1:53 PM
hi,
We can access data in an internal table, data is moved to header line.
If we are having an internal table witout header line, in that case, we have to explicitly create a work area and pass the data from the internal table to that work area and from there, we can access the data.
Ex:
While appending data into internal table with header line.
it_mara1-matnr = 'AAA'.
it_mara1-ersda = sy-datum.
append it_mara1.
clear it_mara1.While appending data into internal table without header line,
we declare a work area.
data: wa_mara like line of it_mara2.
wa_mara-matnr = 'BBB'.
wa_mara-ersda = sy-datum.
append wa_mara to it_mara2.
clear wa_mara. Regards,
Sailaja.
2006 Dec 01 2:00 PM
when you declare an itab with hedaer line, it can hold more than one record in the table during runtime.
Without the header line the itab is just a header it can hold only one record at any point of time.
2006 Dec 01 2:07 PM
with header line
whenever u loop at itab one record at a time is taken into header line and will be processed
data : begin of itab occurs 0 ,
marnr like mara-matnr,
end of itab.
clear itab. --------> this will clear header line
refresh itab -------> this will clear the whole body
*without header line
types : begin of itab,
marnr like mara-matnr,
end of itab.
data : it_itab type standard table of itab,
wa_itab type itab..
clear itab ----> this will clear the whole body
whenever u use without header line , each record will be taken into work area for further processing , workarea is similar to header line
2006 Dec 01 2:11 PM
If you use with header line we need not declare separate work area else we have to declare a work area and use that in all modifying operation of that internal table
2006 Dec 01 2:53 PM
Hi,
somany answers, most are correct, something is definitely wrong (..without header line can hol only one record...- rubbish!).
Let me try to explain in short and add something.
The declaration of internal tables has been extended and modernized a lot - all previous ways still work but they are confusing and obsolete.
All declarations should be like
DATA:
itab TYPE TABLE OF typename.
* OR
itab LIKE TABLE OF fieldname.
This is for simple iternal tables without header line.
Record data can not be accessed directly, only the whole table, i.e.
CLEAR itab
will delete all records.
If you use the addition WITH HEADER LINE, i.e.
DATA:
itab TYPE TABLE OF typename WITH HEADER LINE.
Yo can not use this data object in object-oriented ABAP, because now you have 2 data objects: the internal table itab and the implicit header line itab. The compiler does not know how to distinguish.
When you loop at an internal table WITH HEADER LINE, each record is copied from the table body to the header line. And if you change any value(s), you must move them back to the table boy using MODIFY itab.
If you have a table without header line, it is similar because you can declare a separated header line (called work area) and LOOP into and MOFIFY from this workarea.
You can have huge performance gains since you can LOOP ... ASSIGNING <field-symbol> since release 4.5, just a small addition to the above code
FIELD-SYMBOLS:
<itab> like line of itab.
*...
LOOP AT itab ASSIGNING <itab>.
* if you have a field called recno
<itab>-recno = sy-tabix.
ENDLOOP.
There's not much sense to put the record number in a field called recno, but no copy at all takes place in this step so it will incredibly fast.
And, say, aterward you SORT the table by some other field, recno will still have the original sort orders number.
Best way is to use types and table types like
TYPES:
begin of ty_abc,
a type a,
b type b,
c type c,
end of ty_ abc,
t_abc type table of ty_ abc.
Now you can make your coding very transparent and use the internal table as a structured USING or CHANGING parameter in FORM routines.
There is a lot more to say like additions for STANDARD, SORTED or HASHED tables with keys - First get used to the modern internal tyble concept and then try more...
Regards,
Clemens
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |