Preface – This post is part of the ABAP Beginner series.
Table of Contents
Table Type in SAP ABAP
Before discussing Table Type in SAP ABAP, it will be good to understand Internal Tables first.
An Internal table is a runtime object which holds runtime data in form of table. Its data type is specified by its line type, key and table type. Line type tells the data type of an internal table which can be a structure, a table, an internal table or any data type. Keys are the one which helps to identify each row. Table type specifies how ABAP will access these internal tables i.e. standard table, sorted table & hashed table.
In ABAP Program you can also define Internal Table of type “TABLE TYPE”:
DATA: ITAB TYPE TTYP.
Here TTYP stands for Table Type.
In this particular case you don’t need to take care of any other properties of internal table, it will be taken care by Table Type.
A Table Type in SAP ABAP is a global reusable object which is used to define structure and functional attributes of an internal table in ABAP.
A table type is defined by:
- Line Type: It defines the structure and data type
- Access Mode: kind of internal table e.g. Sorted, Hashed, Indexed
- Keys: Primary & Secondary keys of the table
Creation of Table Type in SAP ABAP:
#Using ABAP Dictionary
Step 01: Open SE11.
Step 02: Click Data Type Radio Button and select Table Type radio button from the given radio buttons. Give your Table Type name starting with Z or Y e.g. “ZBarry_ttype”.
Step 03: Click Create, Enter explanatory description for table type in Short Description e.g. “Table Type for Test”.
Step 04: On Line Type tab, maintain one of the following:
|Line Type||Enter name of any of the following:|
A data element, a structure, a table, a view or even a table type
|Table Type will create a structure similar to this line type.|
|Predefined Type||Enter Data Type, Field Length & decimal places||Length Type can be any predefined data types with any length of field and decimal places. It is similar to the creation of Data Elements.|
|Reference Type||Enter either name of a class, an interface, a generic reference to ANY, OBJECT, or DATA or a reference to a type defined in the Dictionary.||Reference type creates a pointer to data object|
Step 05: On the Initialization and Access tab, maintain the following:
|Initial Line Number||Enter any numeric value if you know the number of records|
Note: You can leave it empty.
|Just Like OCCURS statement in ABAP Internal Table, here too we can specify the number of Initial lines occupied by the internal table.|
|Access: It defines the way Internal table data is accessed while performing the SQL operations on the internal table. Choose one of the following given below:|
|Standard table||It uses linear search to access key.|
|Sorted table||It is sorted internally on basis of key. It uses binary search to access key.|
|Hashed table||It is sorted internally on basis of hashed key. The hash key is generated for each key and this key is used to access data irrespective of index. Hashed keys are generated using Hash Algorithm internally.|
|Index table||In this case the table can be Standard or Sorted. It allows Index access for such table. Index tables are used to define generic parameters of a Subroutine Form & Function Module.|
|Not Specified||It means table can be any among Standard, Sorted or Hashed. The access of Index is not allowed here.|
Step 06: On the Key tab, maintain the following:
|Key Definition: It specifies the Primary key of the table. Select one of the following:|
|Standard key||It defines the key of Table Type on basis of Line type. The Key contains all the character fields of the table line in case of structure, table or view and It is the entire table line in case of Data Element or Reference type.|
|Line type||It defines the entire fields of line type as Primary key.|
|Key components||We can select Primary key from the structure specified by us in Line Type tab earlier. In this case, we need to select the Primary keys.|
|Key not specified||In this case key is Generic. And the table type is called Generic Table Types.|
|Key Category: It tells whether our table type will make an internal table that can store only Unique keys or can have duplicates also.|
|Unique||It means internal table can have only unique records.|
|Non-Unique||It means internal table can have duplicate records too.|
|Not specified||It can be any Unique or Non-Unique. It defines Generic Table Types.|
|Key Components||If you have chosen Key components in Key Definition tab, than you must click on the button Choose components and choose the required fields.|
Note: Here table line means structure of line type.
Combination of Access Mode and Key category that is allowed:
|Access Mode||Key category||Description|
|Not Specified||Not specified||It means that if the access mode is the one as mention here, than the key categories must be chosen from this table only.|
|Index Table||Not specified|
|Sorted Table||Unique, Non-Unique or Not specified|
Step 07: Once all the above fields are maintained, save, check for errors and activate your table type.
Advantages of Table Type in SAP ABAP:
- For an Internal table, you might need to create a local structure using types, state its type, and state its other properties. By using table types, we need to just declare the internal table of type Table Types, rest will be taken care by the table types.
- Being a global object, it can be reused.
Note: Table Types is a vast topic and it needs one more article to explain the rest of the concepts like Ranges Table Types, etc. We will cover them in next article.