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

syntax

Former Member
0 Likes
724

Here I have two syntaxes to decalre an internal table given below.

1.data : begin of itab occurs 0,

lifnr like lfa1-lifnr,

end of itab.

2.types : begin of itab occurs 0,

lifnr like lfa1-lifnr,

end of itab.

data : wa type itab,

body type table of wa.

Among the above syntaxes which one is preferrable in terms of performance and whst is the REASON FOR THAT.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
697

First one.

No impact on performance.

Second one is actually making two internal tables that's why it's useless.

Regards

Nishant

6 REPLIES 6
Read only

Former Member
0 Likes
698

First one.

No impact on performance.

Second one is actually making two internal tables that's why it's useless.

Regards

Nishant

Read only

Former Member
0 Likes
697

First one only...;

In the second one...No need of making two internal tables (wa, body)....

USE like below....

types : begin of itab occurs 0,

lifnr like lfa1-lifnr,

end of itab.

data : wa type table of itab.

Read only

former_member404244
Active Contributor
0 Likes
697

Hi,

There is not much difference for second case ur explicitly defing the work area,whre as in the first one the workarea automatically comes..When u go occurs 0 it will allocate 8KB directly.While using oops concepts generally the second one is used.

Regards,

Nagaraj

Read only

Former Member
0 Likes
697

<b>I) Creating Internal Tables by Referring to Another Table</b>

To create an internal table data object by <b>referring to an existing internal table</b> data type or data object, you use the DATA statement as follows:

Syntax

DATA <f> <type> [WITH HEADER LINE].

You can use the <type> option to refer to a table data type or table data object by using TYPE or LIKE . The data object <f> is declared as an internal table with the same structure.

If you use the WITH HEADER LINE option, the internal table is created with a table work area <f>.

If you want to create an internal table with a header line, the line type cannot directly be an internal table. However, it can be a structure which has internal tables as components

Example:

TYPES: BEGIN OF LINE,

COLUMN1 TYPE I,

COLUMN2 TYPE I,

COLUMN3 TYPE I,

END OF LINE.

TYPES ITAB TYPE LINE OCCURS 10.

DATA TAB1 TYPE ITAB.

DATA TAB2 LIKE TAB1 WITH HEADER LINE.

As shown in Creating Internal Table using Data Types, this example creates a data type ITAB as an internal table. The data object TAB1 has the same structure as ITAB by referring to ITAB using the TYPE parameter of the DATA statement. The data object TAB2 has the same structure by referring to TAB1 using the LIKE parameter of the DATA statement. TAB2 is created with header line. Therefore, the table work area TAB2 can be addressed in the program by using TAB2-COLUMN1, TAB2-COLUMN2, and TAB2-COLUMN3.

III) Creating Internal Tables by Referring to a Structure

To create an internal table data object by referring to an existing line structure, you use the DATA statement as follows:

Syntax

DATA <f> <type> OCCURS <n> [WITH HEADER LINE].

This creates an internal table <f> by using the OCCURS option of the DATA statement. The lines of the internal table have the data type specified in <type>. To specify the data type, you can use either the TYPE or the LIKE parameter.

By using the LIKE parameter to refer to an object defined in the ABAP/4 Dictionary, you can create internal tables which have the same line structure as objects stored in the dictionary, and which reflect the structure of database tables. This is very important when reading and processing database tables

<n> specifies an initial number of lines. Memory is reserved for the number of lines specified as soon as the first line is written to an internal table data object created with type <f>. If more lines are added to an internal table than specified by <n>, the reserved memory expands automatically. If there is not enough space in memory for an internal table, it is written to a buffer or to the disk (paging area).

The features described above are the same as those for creating internal table <b>data types with the TYPES statement.</b>

As an additional feature, you can use the WITH HEADER LINE option with the DATA statement. This creates a table work area <f> with the same structure as the lines of the internal table <f>.

EXAMPLE 1:

DATA FLIGHT_TAB LIKE SFLIGHT OCCURS 10.

This example creates a data object FLIGHT_TAB which has the same structure as the database table SFLIGHT.

EXAMPLE 2:

This example shows you how to create the same internal table using two different procedures.

TYPES VECTOR_TYPE TYPE I OCCURS 10.

DATA VECTOR TYPE VECTOR_TYPE WITH HEADER LINE.

Here, an internal table data type VECTOR_TYPE is created with lines consisting of an elementary type I field is created first. Then, a data object VECTOR is created as an internal table by referring to VECTOR_TYPE. A table work area VECTOR is also created by using the WITH HEADER LINE option. In this case, the table work area consists of one type I field which can be addressed by the name VECTOR.

EXAMPLE 3:

DATA VECTOR TYPE I OCCURS 10 WITH HEADER LINE.

<b>

Ii) Creating Internal Table using Data Types</b>

To create an internal table data type, you use the TYPES statement as follows:

Syntax

TYPES <t> <type> OCCURS <n>.

This creates an internal table data type <t> by using the OCCURS option of the TYPES statement. The lines of the internal table have the data type specified in <type>. To specify the data type of the lines, you can use either the TYPE or the LIKE parameter.

By using the LIKE parameter to refer to an object defined in the ABAP/4 dictionary, you can create internal tables which have the same line structure as objects stored in the dictionary, and which reflect the structure of database tables. This is very important when reading and processing database tables

<n> specifies an initial number of lines. Memory is reserved for the number of lines specified as soon as the first line is written to an internal table data object created with type <t>. If more lines are added to an internal table than specified by <n>, the reserved memory expands automatically. If there is not enough space in memory for an internal table, it is written to a buffer or to the disk (paging area).

Example 1.

TYPES VECTOR TYPE I OCCURS 10.

This example creates an internal table data type VECTOR which has lines consisting of the elementary type I field.

Example 2.

TYPES: BEGIN OF LINE,

COLUMN1 TYPE I,

COLUMN2 TYPE I,

COLUMN3 TYPE I,

END OF LINE.

TYPES ITAB TYPE LINE OCCURS 10.

This example creates an internal table data type ITAB which has lines with the same structure as the field string LINE.

Example 3.

TYPES VECTOR TYPE I OCCURS 10.

TYPES: BEGIN OF LINE,

COLUMN1 TYPE I,

COLUMN2 TYPE I,

COLUMN3 TYPE I,

END OF LINE.

TYPES ITAB TYPE LINE OCCURS 10.

TYPES: BEGIN OF DEEPLINE,

TABLE1 TYPE VECTOR,

TABLE2 TYPE ITAB,

END OF DEEPLINE.

TYPES DEEPTABLE TYPE DEEPLINE OCCURS 10.

This example creates the same internal table data types (VECTOR and ITAB) as in the above examples. It then creates a data type DEEPLINE as a field string which contains these internal tables as components. Via this field string, a data type DEEPTABLE is created as internal table. Therefore, the elements of this internal table are themselves internal tables.

Reward if helpful.....

Read only

Former Member
0 Likes
697

hi,

there is no such performance issue in any of these.

you can use whichever you want according to your requirement.

In your 1st syntax itab will itself work as work area.

in 2nd itab will work as work area as well, but you need one more work area you can declare stmt data : wa type itab,

and body here will work as internal table.

that means in second syntax you have 2 itabs : itab and body. and 2 work areas: itab and wa.

Read only

Former Member
0 Likes
697

Hi,

second one u have to write like this.

types : begin of itab," occurs 0,

lifnr like lfa1-lifnr,

end of itab.

data : wa type itab,

body type table of wa.

the best one is second one.because,header line will reduce the performance.

also header line concept is not supported by OOps concepts.

rgds,

bharat.