SAP ABAP Tables – Types and Fields

FREE Online Courses: Your Passport to Excellence - Start Now

In this tutorial, we’ll be learning what are Tables, Table Fields in ABAP, Types of SAP ABAP Tables, How to create Tables in Data Dictionary, What are Internal Tables, Purpose of Internal Tables, Types of Internal Tables and How to create, modify internal tables.

Let’s start our journey!!!!

What are Tables in ABAP?

  • A table is a 2D structure that can be created independently of the database, comprising a grid of rows and columns
  • Rows of a table are called records and columns are called fields
  • Rows are individual entries, while columns contain data types & domains

Tables in SAB ABAP

Table Fields in ABAP

Tables can have several fields, which in turn contain many elements. Let’s look at a few of these fields –

FIELD DESCRIPTION
Field NameField name is the name of the field, beginning with a letter and containing alphabets, numbers and/or underscore ‘_’. The maximum length allowed is 16 characters
Key FlagThis is a checkpoint use to determine if a particular field is part of a key field or not.
Field typeIt is the data type of a field
Field LengthThis is the length or count of characters that can be used for a field.
Decimal PlacesDecimal places are the number of integers that can be added after the floating point.
Short TextThis is used for description of whatever field it is related to

Types of Tables in ABAP

There are three types of tables in ABAP. They are –

1. Transparent tables in SAP ABAP

  • Transparent tables contain the master data i.e. information source of all data elements in the database.
  • It is said to have a ‘one-to-one’ relationship with data dictionary fields.
  • This means that the name and number of fields from the table are equivalent to those from the data dictionary table.
  • Transparent tables usually store application data.

2. Cluster tables in SAP ABAP

  • Cluster tables are said to have a ‘many-to-one’ relationship with the data dictionary table.
  • Here, there are said to be many tables from the database for one table in the dictionary.
  • All the tables are stored as a cluster within one table in the database.
  • Cluster tables usually store system data.

3. Pooled tables in SAP ABAP

  • Pooled tables are said to have a ‘many-to-one’ relationship with the data dictionary table.
  • This means that if you consider one field from the pooled table database, there are many equivalent ones from the ABAP dictionary.
  • Hence, the tables might not have a common primary key field.
  • Pooled tables usually store system data.

How to create Tables in Data Dictionary

  • A user-defined table must start with ‘Z’ or ‘Y’
  • The name may contain alphabets, numbers and underscores

Here are the steps to create a new table in SAP ABAP –

1. Open the SAP application system

2. Enter t-code ‘SE11’ to open the Data Dictionary screen

3. Click on the first radio button ‘Database Table’ and enter the name you want to give the table (must start with ‘Z’ or ‘Y’!)

How to create Tables in Data Dictionary

4. Click on the ‘Create’ button below. This opens a popup window

5. Give a short description of what the table will be about

6. Enter Delivery Class as ‘A’ (default)

7. Click on the option – ‘Display/Maintenance Allowed’ so that you can edit it later if needed

How to create Tables in Data Dictionary in ABAP

8. Click on ‘Save’

9. Select the tab called ‘Fields’ and enter field & data element name

create tables in SAP ABAP

10. Click on ‘Save’

11. Table is created – you can now activate it

What are Internal Tables in SAP ABAP?

  • Internal tables are similar to database tables in terms of structure – rows and columns.
  • However, they do not store any data in the memory i.e. all the data displayed by internal tables is temporary.
  • Internal tables are usually used to create manipulations in data and updates required by aggregation methods.
  • Internal tables can also be classified as both data objects and data types.

Purpose of ABAP Internal Tables

There are many uses that an internal table can embibe. Here are some of them –

  • Internal tables can be used to aggregate data and summarize data from memory.
  • They can be used to display results of expressions calculated via tables that may be useful for a specific purpose.
  • They may hold data for quick access e.g. if you want to check data only from a few fields rather than all, you may filter out the rest in an internal table and use the relevant data only.
  • Internal tables are multipurpose and can be used as data types as well as data objects.

Types of SAP ABAP internal tables

SAP ABAP Internal Tables

1. Standard Tables in ABAP

  • Standard tables are accessed linearly, using a progressive index
  • The key of the table is usually non unique
  • Hence the rows are added one after the other, at the very end
  • The entries can be accessed using index or key
  • Uses APPEND command to add records

2. Sorted Tables in ABAP

  • Sorted tables, as the name goes, have sorted entries
  • The rows are sorted using key, which is unique
  • Hence duplicate entries are not allowed
  • Uses INSERT command to add record using data and key

3. Hashed Tables in ABAP

  • They do not have linear index, in fact they are non-indexed
  • Instead, hashed tables are stored using a hash algorithm
  • They are usually used when the volume of data to be stored or processed is very large

How to create and modify internal tables in ABAP

In the ‘DATA’ statement in ABAP, internal tables can be created by using keywords ‘TABLE OF’ as shown –

REPORT ZR_SS_DATAFLAIR_SAMPLE_001.

TYPES: BEGIN OF ty_dataflair,
       id(5)    TYPE n,
       name(10) TYPE c,
       END OF ty_dataflair.

DATA: df_dataflair TYPE ty_dataflair.

"Referring to local data type
DATA: df1 TYPE TABLE OF ty_dataflair.
"Referring to local data object
DATA: df2 LIKE TABLE OF df_dataflair.
"Referring to data type in ABAP dictionary
DATA: df3 TYPE TABLE OF mara.

To add to the internal table, use APPEND statement as follows – 

REPORT ZR_SS_DATAFLAIR_SAMPLE_001.

TYPES: BEGIN OF ty_dataflair,
       id(5)    TYPE n,
       name(10) TYPE c,
       END OF ty_dataflair.

DATA: df_dataflair TYPE ty_dataflair.

DATA: it TYPE TABLE OF ty_dataflair.

df_dataflair-id    = 1.
df_dataflair-name  = 'DATA'.
APPEND df_dataflair TO it.

df_dataflair-id    = 2.
df_dataflair-name  = 'FLAIR'.
APPEND df_dataflair TO it.

df_dataflair-id    = 3.
df_dataflair-name  = 'ABAP'.
APPEND df_dataflair TO it.

Summary

Hence in this tutorial we learnt about the building blocks of a relational database – tables. We learnt about the different types and uses of database tables.

We also learnt about internal tables, why they are important and how to create both types of tables in SAP.

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *