‎2006 Dec 27 5:31 AM
Hi frnds,
what is the difference between bothe the types of declararion i mean to say technical point of view.
1) DATA : BEGIN OF ITAB 0CCURS 0,
MATNR LIKE MARA-MATNR,
ERNAM LIKE MARA-ERNAM,
END OF ITAB.
2)
TYPES : BEGIN OF T_TAB,
MATNR LIKE MARA-MATNR,
ERNAM LIKE MARA-ERNAM,
END OF T_TAB.
data it_tab type table of t_tab.
Thnking u all.
regards,
satish
‎2006 Dec 27 5:35 AM
1) it_tab will not have a Header line where as itab will have one.
‎2006 Dec 27 5:35 AM
Hi,
OCCURS 0 declares an internal table with work area whereas the second declration dont have an header .
We should always use the second type declaration ans declare an explicit work area like data : wa type it_tab.
Hope this helps.
‎2006 Dec 27 5:35 AM
Hi,
In the first case, your internal table has a header line & the second doesn't have it.
‎2006 Dec 27 5:36 AM
hi,
chk this u will get the idea.
*&---------------------------------------------------------------------*
*& Report ZTYPES *
*& *
*&---------------------------------------------------------------------*
REPORT ZTYPES .
* Table declaration (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.
*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)
* Build internal table and work area from existing internal table
DATA: it_datatab LIKE tab_ekpo OCCURS 0, "old method
wa_datatab LIKE LINE OF tab_ekpo.
* Build internal table and work area from existing internal table,
* adding additional fields
TYPES: BEGIN OF t_repdata.
INCLUDE STRUCTURE tab_ekpo. "could include EKKO table itself!!
TYPES: bukrs TYPE ekpo-werks,
bstyp TYPE ekpo-bukrs.
TYPES: END OF t_repdata.
DATA: it_repdata TYPE STANDARD TABLE OF t_repdata INITIAL SIZE 0, "itab
wa_repdata TYPE t_repdata. "work area (header line)http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb3660358411d1829f0000e829fbfe/frameset.htm
Regards
Anver
‎2006 Dec 27 5:38 AM
Hi,
First type of decleration hold WA & body of table
Second decleration hold only body of table.
‎2006 Dec 27 5:41 AM
Hi All,
Thnk u for ur replies.
suppose i m declaring the second declaration as
data it_tab type table of t_tab with header line.
Then wht is the difference now.
regards,
satish
‎2006 Dec 27 5:44 AM
Hi,
DATA: BEGIN OF <itab> OCCURS <n>,
...
<fi> ...
...
END OF <itab>.
This statement declared an internal table <itab> with the line type defined following the OCCURS addition. Furthermore, all internal tables had header lines.
The number <n> in the OCCURS addition had the same meaning as in the INITIAL SIZE addition from Release 4.0. Entering 0 had the same effect as omitting the INITIAL SIZE addition. In this case, the initial size of the table is determined by the system.
The above statement is still possible in Release 4.0, and has roughly the same function as the following statements:
TYPES: BEGIN OF <itab>,
...
<fi> ...,
...
END OF <itab>.
DATA <itab> TYPE STANDARD TABLE OF <itab>
WITH NON-UNIQUE DEFAULT KEY
INITIAL SIZE <n>
WITH HEADER LINE.
In the original statement, no independent data type <itab> is created. Instead, the line type only exists as an attribute of the data object <itab>.
Since Release 3.0, it has been possible to create table types using
TYPES <t> TYPE|LIKE <linetype> OCCURS <n>.
and table objects using
DATA <itab> TYPE|LIKE <linetype> OCCURS <n> [WITH HEADER LINE].
The effect of the OCCURS addition is to construct a standard table with the data type <linetype>. The line type can be any data type. The number <n> in the OCCURS addition has the same meaning as before Release 3.0. Before Release 4.0, the key of an internal table was always the default key, that is, all non-numeric fields that were not themselves internal tables.
The above statements are still possible in Release 4.0, and have the same function as the following statements:
TYPES|DATA <itab> TYPE|LIKE STANDARD TABLE OF <linetype>
WITH NON-UNIQUE DEFAULT KEY
INITIAL SIZE <n>
[WITH HEADER LINE].
They can also be replaced by the following statements:
When you create a standard table, you can use the following forms of the TYPES and DATA statements. The addition INITIAL SIZE is also possible in all of the statements. The addition WITH HEADER LINE is possible in the DATA statement.
Generic Standard Table Type:
TYPES <itab> TYPE|LIKE [STANDARD] TABLE OF <linetype>.
The table key is not defined.
Fully-Specified Standard Table Type:
TYPES <itab> TYPE|LIKE [STANDARD] TABLE OF <linetype>
WITH [NON-UNIQUE] <key>.
The key of a fully-specified standard table is always non-unique.
Short Forms of the DATA Statement :
DATA <itab> TYPE|LIKE [STANDARD] TABLE OF <linetype>.
DATA <itab> TYPE|LIKE [STANDARD] TABLE OF <linetype>
WITH DEFAULT KEY.
Both of these DATA statements are automatically completed by the system as follows:
DATA <itab> TYPE|LIKE STANDARD TABLE OF <linetype>
WITH NON-UNIQUE DEFAULT KEY.
The purpose of the shortened forms of the DATA statement is to keep the declaration of standard tables, which are compatible with internal tables from previous releases, as simple as possible. When you declare a standard table with reference to the above type, the system automatically adopts the default key as the table key.
Fully-Specified Standard Tables:
DATA <itab> TYPE|LIKE [STANDARD] TABLE OF <linetype>
WITH [NON-UNIQUE] <key>.
The key of a standard table is always non-unique.
Regards,
Amit
‎2006 Dec 27 5:44 AM
‎2006 Dec 27 5:45 AM
hi,
* Build internal table and work area from existing internal table,
* adding additional fields
TYPES: BEGIN OF t_repdata.
INCLUDE STRUCTURE tab_ekpo. "could include EKKO table itself!!
TYPES: bukrs TYPE ekpo-werks,
bstyp TYPE ekpo-bukrs.
TYPES: END OF t_repdata.
DATA: it_repdata TYPE STANDARD TABLE OF t_repdata INITIAL SIZE 0, "itab
wa_repdata TYPE t_repdata. "work area (header line)Regards
Anver
‎2006 Dec 27 5:47 AM
Hi ,
In this type of declaration also the table it_itab will have header line so just declaration style is different in this case.
Regards
Ashutosh
Reward points if helpful
‎2006 Dec 27 5:48 AM
hi satish,
in first example a internal table of name itab will be created directly. in second example u need to use data statement to create internal table.
DATA : BEGIN OF ITAB 0CCURS 0,
MATNR LIKE MARA-MATNR,
ERNAM LIKE MARA-ERNAM,
END OF ITAB.
this type of coding is used when structure u create is going to be used only once.
a internal table Itba will be created.
memeory area will be allocated for ITAB.
where
TYPES : BEGIN OF T_TAB,
MATNR LIKE MARA-MATNR,
ERNAM LIKE MARA-ERNAM,
END OF T_TAB.
data it_tab type table of t_tab.
this code is used to create many internal table of T_TAB structure type.
here data statement is required to create internal table.
no memory area will be created until u use data statement.
‎2006 Dec 27 5:57 AM
Hi vickram,
once we give data statement then memory will be allocated then will there be any diff between the two.
regards,
satish
‎2006 Dec 27 6:03 AM
hi,
if u declare with the data : begin of itab occurs 0,
this will create the internal table with the header line
and takes structure from standard.
if u declare with the types u are creating the strucutre in your
program and using that structure .
regards.
Praveen
‎2006 Dec 27 6:04 AM
Hi ,
I learnt from a book that if we declare like this
DATA : BEGIN OF ITAB 0CCURS 0,
MATNR LIKE MARA-MATNR,
ERNAM LIKE MARA-ERNAM,
END OF ITAB.
it will take 8kb of memory initially . whereas
TYPES : BEGIN OF T_TAB,
MATNR LIKE MARA-MATNR,
ERNAM LIKE MARA-ERNAM,
END OF T_TAB.
Data : it_tab type table of t_tab.
in this type it will take 30 bytes (18 + 12) of memory initially .
Cheers .
‎2006 Dec 27 6:07 AM
Hi,
OCCURS 0 declares an internal table with work area whereas the second declration dont have an header .
We should always use the second type declaration ans declare an explicit work area like data : wa type it_tab.
regards,
kumar
‎2006 Dec 27 6:49 AM
Hi
The main difference is in "Header Line".
In the first case, there will be a header line by default.
In the second case, you are creating a type declaration, with the necessary fields and then creating an internal table of that 'type'. So this will not have any header line.
It is always advisable to use the second option i.e. first create a type declaration and then decalre an internal table of that type. Also create an expilcit Work Area of the same type declaration. This is the "Best Practice" used.
Never use header line as the performance of the code comes down. Always use explicit Work Area.
PS: If this answer is useful, plz provide Reward Points.
‎2006 Dec 27 8:20 AM
The basic difference would be ....the first declaration of internal table will have a Header where as the type declaration will not have a header...
...morover if u have declared using "type"... while looping at the internal table u will have to loop into a wor areak to read and access it for computation....as for the first its not needed.