Before release 3.0 internal tables were declared as shown below.
DATA: BEGIN OF <int_tab> OCCURS <n>,
END OF <int_tab>.
Hashed Tables, Sorted Tables and Key access were introduced only in release 4.0. Standard tables existed before release 3.0, they all had a header line and a flat-structure line type. In release 4.0 the above syntax is still supported, the new syntax is as follows.
TYPES: BEGIN OF <int_tab>,
END OF <int_tab>.DATA <int_tab> TYPE STANDARD TABLE OF <int_tab>
WITH NON-UNIQUE DEFAULT KEY
INITIAL SIZE <n>
WITH HEADER LINE.
The header line addition works as a work area. Basically it is an additional data object with the same name and line type as the internal table. Using an Internal table with header line does lead to a confusion as the internal table and the header line share the same name. Hence in the code if data is to be moved to the body of the internal table and not to the header line then the table needs to be referred as int_tab[]. It is a therefore good practice NOT TO USE a header line for an internal table. It is better to declare a separate work area.
In the current version WITH HEADER LINE addition is obsolete; and hence it should not be used. |
DATA: BEGIN OF int_tab OCCURS 0, | Old way of declaring an internal table. Here the OCCURS 0 is the same as INTIAL SIZE <n> |
* Types Declaration | New way. Declare TYPES first. |
* Work Area Declaration | Declare a WORK AREA, this is useful in terms of passing data to the internal table. |
TYPES itab TYPE STANDARD TABLE OF ty_ord. | Declaration of table type itab. |
* Internal Table Declaration | Declaration of the actual INTERNAL TABLE |
Sample Code for ABAP INTERNAL TABLE DECLARATION.
* Types Declaration
TYPES: BEGIN OF ty_ord,
vbeln like vbak-vbeln,
matna like mara-matnr,
END OF ty_ord.* Work Area Declaration
DATA wa_ord TYPE ty_ord.TYPES itab TYPE STANDARD TABLE OF ty_ord.
* Internal Table Declaration
Data int_ord TYPE itab.move: '0000123456' to wa_ord-vbeln.
append wa_ord to int_ord.
move: '0000123457' to wa_ord-vbeln.
append wa_ord to int_ord.Write:/ wa_ord.
No comments:
Post a Comment