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

reg: internal table?

Former Member
0 Likes
701

hello friends?

i have one basic doubts,

please clear this things,

what are all the ways we can create the internal table?

how we create internal table using data statement?

how we create internal table using types statement?

what is the difference between these two methods?

5 REPLIES 5
Read only

Former Member
0 Likes
644

Hi selva,

1. what are all the ways we can create the internal table?

a) using BEGIN OF

b) using some data dictionary table/structure

c) using types and then data

2. how we create internal table using data statement

DATA : T001 LIKE T001 OCCURS 0 WITH HEADER LINE.

DATA : T001 LIKE TABLE OF T001 WITH HEADER LINE.

DATA : BEGIN OF T001 OCCURS 0,

F1(10) TYPE C,

END OF T001.

3. how we create internal table using types statement

TYPES : BEGIN OF MYTYPE,

F(10) TYPE C,

END OF MYTYPE.

DATA : MYITAB TYPE MYTYPE OCCURS 0 WITH HEADER LINE.

4. what is the difference between these two methods?

For practical purpose,

there is no difference.

regards,

amit m.

Read only

Former Member
0 Likes
644

hi

good

1- there is two kind of internal table

a-internal table with header line

b-internal table withoug heder line

2-DATA: BEGIN of ITAB OCCURS 0,

3-DATA: BEGIN of ITAB OCCURS 0,

FIDLEDS,

END OF ITAB.

DATA: ITAB1 TYPE ITAB.

4-IN DATA YOU R DIRECTLY DECLARING AN INTENAL TABLE,

but in case of TYPE you r using the reference of the first table.

thanks

mrutyun^

Read only

aris_hidalgo
Contributor
0 Likes
644

Hi Selva,

It really depends on your company standards and your personal preference. Anyway, here are the ways you can declare an internal table:

*TYPES

types: begin of itab,

f1(20) type c,

f2 type i,

f3 type i,

end of itab.

data: it_itab type standard table of itab with header line.

"OR YOU CAN DECLARE YOUR ITAB W/O HEADER LINE

data: it_itab type standard table of itab.

field-symbols: <fs_itab> like line of it_itab.

*DATA

data: begin of itab occurs 0,

f1(20) type c,

f2 type i,

f3 type i,

end of itab.

I always go types since it is more 'formal' for me and I am using ABAP OO in some of my reports.

Hope this helps...

P.S. Please award points for useful answers.

Read only

Former Member
0 Likes
644

Hello,

Case 1: using TYPES

( This is the suggested way of declaring internal table)

TYPES: BEGIN OF ty_itab,

matnr type matnr,

ENDOF ty_itab.

DATA: lwa_itab type ty_itab,

gt_itab like standard table of lwa_itab.

Case 2:

( This is not suggested)

DATA: BEGIN OF dt_itab occurs 10, ( or occurs 0)

matnr type matnr,

ENDOF dt_itab.

Case 2 is not suggested because when ever the internal table is appended the internal table length is increased by size 10 rows ( Just think about eh wastage of space if you have n fields in the internal table).

But in case 1, the internal table row will be created only when you append to the table.

And also it is not suggested to use occurs or with header line clause, as it decreases the performance.

Hope this clarifies.

Regs,

Venkat Ramanan N

Message was edited by: Venkat Ramanan Natarajan

Read only

Former Member
0 Likes
644

FYI..

DATA - Defining an Internal Table

Variants:

1. DATA itab TYPE itabtype [WITH HEADER LINE].

2. DATA itab {TYPE tabkind OF linetype|

LIKE tabkind OF lineobj}

WITH [UNIQUE|NON-UNIQUE] keydef

[INITIAL SIZE n] [WITH HEADER LINE].

3. DATA itab {TYPE TABLE OF linetype|LIKE TABLE OF lineobj}.

4. DATA itab TYPE RANGE OF type.

DATA itab LIKE RANGE OF f.

5. DATA itab [TYPE linetype|LIKE lineobj] OCCURS n

[WITH HEADER LINE].

6. DATA: BEGIN OF itab OCCURS n,

...

END OF itab [VALID BETWEEN f1 AND f2].

In an ABAP Objects context, a more severe syntax check is performed that in other ABAP areas. See New naming conventions and LIKE references to Dictionary Types not allowed.

Effect

Defines an internal table.

To fill and process internal tables, use the statements INSERT, APPEND, READ TABLE, LOOP, SORT, and so on.

The OCCURS or INITIAL SIZE parameter (OCCURS value) determines the number of lines that are created when the table itself is created. However, the table is extended dynamically on demand. For details, refer to Performance Notes for Internal Tables. The OCCURS value, has no other semantic meaning (apart from one exception in the APPEND SORTED BY statement). If you do not specify an INIT IAL SIZE , the system uses the default value 0.

If you specify WITH HEADER LINE, the table is created with a header line, that is, a field with the same name. It has the same type as the line type of the table.

This addition is not allowed in an ABAP Objects context. See Tables with header line not allowed.

Variant 1

DATA itab TYPE itabtype [WITH HEADER LINE].

Effect

itabtype must be an internal table type that you have already defined using TYPES. The statement creates an internal table in the program with this type.

In general, the type specification for the table object must be complete. The exception to this is a standard table, in which the key definition may be missing. In this case, the system automatically uses a default key.

Example

Creating a hashed table by referring to an existing table type:

TYPES: BEGIN OF STRUC, NAME(10), AGE TYPE I, END OF STRUC,

HTAB TYPE HASHED TABLE OF STRUC WITH UNIQUE KEY NAME.

DATA : PERSONS TYPE HTAB.

Variant 2

DATA itab {TYPE tabkind OF linetype|LIKE tabkind OF lineobj} WITH [UNIQUE|NON-UNIQUE] keydef

[INITIAL SIZE n] [WITH HEADER LINE].

Effect

Creates an internal table in the program with the type tabkind. Since there are no generic field definitions, you cannot use the table types ANY TABLE or INDEX TABLE.

The structure of the table lines is defined by the type linetype if you use a TYPE reference) or by the type of the referred object lineobj (when you use a LIKE reference).

The same rules apply to the UNIQUE and NON-UNIQUE additions in the DATA statement as in a TYPES definition. You may only omit the definition when defining a standard table.

If you do not specify the INITIAL SIZE the system uses a default initial size of 0.

Variant 3

DATA itab {TYPE TABLE OF linetype|LIKE TABLE OF lineobj}.

Effect

This is a shortened form of the definition of a standard table. It corresponds to

DATA itab {TYPE STANDARD TABLE OF linetype|

LIKE STANDARD TABLE OF lineobj} WITH DEFAULT KEY.

or the old definition (compare variant 4)

DATA itab {TYPE linetype|LIKE lineobj} OCCURS 0.

Variant 4

DATA itab TYPE RANGE OF type. DATA itab LIKE RANGE OF f.

Additions:

1. ... INITIAL SIZE n

2. ... WITH HEADER LINE

Effect

Creates an internal table itab with table type STANDARD. The line type is a structure with the following components:

SIGN(1) TYPE C

OPTION(2) TYPE C

LOW TYPE type bzw. LIKE f

HIGH TYPE type bzw. LIKE f

Addition 1

...INITIAL SIZE n

Effect

The INITIAL SIZE specification determines how many table lines are created when the table itself is created. The table is also dynamically expanded as required. For further information, refer to Performance Notes for Internal Tables. The INITIAL SIZE value has no semantic meaning (apart from one exception in the ei APPEND SORTED BY statement). If you do not specify the INITIAL SIZE, the system uses the default value 0.

Addition 2

... WITH HEADER LINE

This addition is not allowed in an ABAP Objects context. See Tables with Header Lines Not Allowed.

Effect

Creates an internal table and a header line for it, that is, a field with the same name as the internal table and the same type as the line type of the internal table.

Variant 5

DATA itab [TYPE linetype|LIKE lineobj] OCCURS n [WITH HEADER LINE].

This variant is not allowed in an ABAP Objects context. See Declaration with OCCURS not allowed.

Effect

This variant exists to ensure compatibility with Release 3.x. If you do not specify a line type, the system uses type C with length 1. Otherwise, the variant is the same as

DATA itab {TYPE STANDARD TABLE OF linetype|

LIKE STANDARD TABLE OF lineobj}

INITIAL SIZE n [WITH HEADER LINE].

Example

TYPES: BEGIN OF LINE_TYPE,

NAME(20) TYPE C,

AGE TYPE I,

END OF LINE_TYPE.

DATA: PERSONS TYPE LINE_TYPE OCCURS 20,

PERSONS_WA TYPE LINE_TYPE.

PERSONS_WA-NAME = 'Michael'. PERSONS_WA-AGE = 25.

APPEND PERSONS_WA TO PERSONS.

PERSONS_WA-NAME = 'Gabriela'. PERSONS_WA-AGE = 22.

APPEND PERSONS_WA TO PERSONS.

The internal table PERSONS now contains two entries.

Variant 6

DATA: BEGIN OF itab OCCURS n, ...

END OF itab [VALID BETWEEN f1 AND f2].

This variant is not allowed in an ABAP Objects context. See Declaration with OCCURS not allowed.

Effect

Creates an internal table itab with type STANDARD and a header line. The line type consists of the fields between "BEGIN OF itab OCCURS n" and " END OF itab".

Use the VALID BETWEEN f1 AND f2 addition to specify that the components f1 and f2 of the internal table itab contain a line-based validity interval. You can only use this addition in conjunction with the PROVIDE statement.

Example

DATA: BEGIN OF PERSONS OCCURS 20,

NAME(20),

AGE TYPE I,

END OF PERSONS.

PERSONS-NAME = 'Michael'.

PERSONS-AGE = 25.

APPEND PERSONS.

PERSONS-NAME = 'Gabriela'.

PERSONS-AGE = 22.

APPEND PERSONS.

The internal table consists of two entries. PERSONS also has a header line (work area), which is an interface between the program and the actual table contents.

Additional help

Internal Table Objects

Ramesh