Reputation: 502
Why we use Table Type in SAP/ABAP? We can declare as type of table as shown below.
DATA it_doc TYPE TABLE OF table_name.
And if I want to store for specific attribute of table, I can use structure type.
TYPES: BEGIN OF st_student,
sid TYPE i,
sname TYPE c LENGTH 8,
END OF st_student.
DATA student TYPE st_student.
Is there any performance difference between table type and structure?
Upvotes: 2
Views: 12050
Reputation: 536
If I understand you correctly, you are talking about table types in the data dictionary. Since you can use the statement TYPE TABLE OF <structure>
it might seem unintuitive to create a table type on top of that. However you need this table type if you want to pass a whole table as an argument to a Function Module or Class Method.
For example, you cannot write the following:
methods PASS_TABLE
returning
value(rt_table) TYPE TABLE OF <structure> .
In this case you have to use a dictionary table type:
methods PASS_TABLE
returning
value(rt_table) TYPE dict_table_type .
Upvotes: 4
Reputation:
No, tables and structures are actually very different, so your concerns about performance are a bit unnecessary. As I stated in my comment, a table is a list of elements.
You want to store information about a school class. Your application should be able to store data like name, birthdate, gender etc. of one student. To group those fields together, one would use a structure:
TYPES:
BEGIN OF student,
name TYPE string,
birth TYPE d,
gender TYPE char1,
END OF student.
Now you can declare a variable of type student
and assign data like that:
DATA stud1 TYPE student.
stud1-name = 'Joe'.
...
You now want to put students together in a classroom. You'll need an internal table for this.
TYPES classroom TYPE STANDARD TABLE OF student WITH EMPTY KEY.
" ignore STANDARD and WITH EMPTY KEY for now
DATA e3fi TYPE classroom.
" fill table here
DATA joe TYPE student.
" init joe
APPEND joe TO e3fi.
DATA susan TYPE student.
" init susan
APPEND susan TO e3fi
After that your classroom e3fi
contains two students susan
and joe
. Each of these students has individual name, birthdate and so on.
Upvotes: 4