Where to use table types and where structures?

10,335

Solution 1

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 .

Solution 2

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.

Example

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.

Share:
10,335
divScorp
Author by

divScorp

SAP/ABAP Developer.

Updated on June 14, 2022

Comments

  • divScorp
    divScorp almost 2 years

    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?

    • Admin
      Admin over 6 years
      A table is more or less like a list of elements. In your example, one structure represents one student. A table could be used to store multiple students.
    • Admin
      Admin over 6 years
      I think, I don't get the question. Could you try to elaborate a bit more about your thoughts?
    • divScorp
      divScorp over 6 years
      @lausek if i want internal table exactly as table, we can use to declare as type of table. And if i want internal table with specific column, we can use either Table Type or STRUCTURE type. So my question is, what is use of table type if we have structure. As i understand TT is same as structure. And i thought that structure is faster than TT on performance basis.