Database Tables and Structures

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Every business application stores its data in tables: the expense claims of this section are rows in a table, and the program reads and changes them through ABAP SQL. In ABAP you do not create those tables on the database yourself. You describe a table once in the ABAP Dictionary, the system’s central catalogue of type definitions, and the system creates the real table on the database when you activate the description. The same dictionary also holds structures, which are named groups of fields without any rows, and which describe the shape of one row. A newcomer meets both on the first day of work with SAP data, because every program, every CDS view and every service ends up reading a dictionary table. This page explains what a database table and a structure are, how a table is built from key fields and a client field, which technical settings and categories you must choose, how a structure is reused with an include or extended with an append structure, and why pool and cluster tables are legacy. It is written against Standard ABAP release 8.16 and ABAP for Cloud Development release 9.20 (2608). Tables and structures defined in source code with DEFINE TABLE and DEFINE STRUCTURE work in ADT on classic systems from SAP NetWeaver AS ABAP 7.52 and 7.5 and apply to ABAP Cloud, classic Standard ABAP, on premise and the Public Edition alike. The SE11 screens that did this job before are described on Classic Tools: SE80 and SE11.

Before you read

  • Data Types and Data Objects: structures, elementary types and how a type is used to declare a variable.

  • ADT (Eclipse) Setup: the editor in which the source of a dictionary object is written.

  • Classic Tools: SE80 and SE11: the older screens that edit the same dictionary objects.

  • Data elements and domains, which give a field its meaning, have a page of their own that comes just before this one in the section; this page only uses them. Foreign keys and indexes, and views, have pages that come after it.

Key terms

  • ABAP Dictionary: the central place where tables, data elements, structures and other type definitions are kept.

  • DDIC database table: the dictionary description of a table, from which the system creates the real table on the database.

  • Transparent table: a table that exists on the database under its own name, with the same columns as its dictionary definition.

  • DDIC structure: a named group of fields that describes one row and holds no data of its own.

  • Client field: the first key column of a client-dependent table, which separates the data of different clients of one system.

  • Delivery class: the table setting that says what kind of data the table holds and how that data is transported and copied.

  • Enhancement category: the setting that says whether and how a structure or table may be extended with more fields.

  • Append structure: an extra set of fields that adds to an existing structure or table without changing the original object.

Tables and structures in plain words

Think of a ledger book. A database table is the ledger with all its pages: it holds many rows, each row has the same columns, and the rows are kept permanently on the database. A structure is only the printed header of one page: the list of columns and their types, with no rows underneath. The ABAP Dictionary stores both as definitions. The Keyword Documentation says that the main task of dictionary structures is to describe database tables and views and, at the same time, to be visible everywhere else, so that interface parameters and data objects can be typed with them.

A dictionary database table is therefore two things at once. For the database it is a physical table, which the system creates when you activate the definition. For an ABAP program it is a structure type, so you can declare a variable TYPE zexp_claim to hold one row, and you can also read and change its rows with ABAP SQL. The Keyword Documentation defines it as a database table in the ABAP Dictionary, with a unique primary index and optional secondary indexes, that is generally defined as a transparent table in the database of the application server.

A dictionary object must be activated before it can be used. Until you activate a changed definition, other objects keep working with the previous active version, and a dictionary object can be deleted only when nothing uses it any more.

The next diagram shows how the pieces of the example table of this page fit together. The structure of the claim row holds a client field, the key, plain fields, an included audit structure and an append structure that a later development adds.

flowchart TD T[Table ZEXP_CLAIM] --> C[client: first key field] T --> K[claim_id: key field] T --> F[employee_id, status, currency_code, total_amount] T --> I[include ZEXP_S_AUDIT: created_by, created_at] I -. extended by .-> A[append structure ZEXP_S_AUDIT_EXT] T --> S[Technical settings: data class, size category, buffering]

Transparent tables

A transparent table is the normal kind. The database holds a table with the same name and the same columns as the dictionary definition, so the data can be read with plain SQL from outside the ABAP system as well. In the source-based table editor of ADT you pick the table category with the annotation @AbapCatalog.tableCategory, and the ADT user guide lists two values: #TRANSPARENT, the default for new tables, and #GLOBAL_TEMPORARY, a special transparent table used only for temporary data. These are the only categories offered when you create a table in ADT.

Pool and cluster tables are legacy

Older systems had two more table categories that stored data in a different way from a transparent table. A pooled table kept its rows together with those of other pooled tables in one shared database table, a table pool. A cluster table kept the rows of several tables, linked by a common key, in one compressed field of a table cluster. The dictionary hid this from programs, but the database could not read the data with ordinary SQL. The best known surviving example is the HCM cluster table PCL2 that holds payroll and time results: SAP describes it as storing data in compressed binary strings that can be read only with the ABAP statement IMPORT, and offers declustering, which creates a transparent table for each internal table in the cluster and copies the data into it, so that normal SQL and database aggregations work.

Nothing on this page needs you to create a pool or cluster table, and you cannot: a new table in ADT is transparent. You will meet them when you read the data model of an older system, and the dictionary adjustment tool SPDD still lists pooled and cluster tables among the dictionary objects it handles. How much of the standard data model of your release is already transparent is a question for the simplification information of that release, which this page does not repeat.

The client field

One SAP system can hold the data of several independent clients, which are separate business views on one installation, such as a test client and a production-like client. A table whose rows belong to one client is client-dependent, and its first key field is the client field, of the built-in dictionary type abap.clnt. By convention it is named client in the source (older tables call it MANDT, from the German word for client). You never fill it yourself: ABAP SQL restricts every read and write on a client-dependent table to the logon client automatically, and the client of a session cannot be changed from application code. The SAP cheat sheet on the ABAP Dictionary adds that tables in the delivery class A are generally client-dependent.

Two consequences matter for a beginner. First, the client field is a real key field, so it is the first line of the key in the source, as the example below shows. Second, adding a client field to a table that already has data is not a small change: the classic dictionary documentation warns that inserting a client field converts the table and copies its data to every client listed in the client table T000. Decide on the client field when you create the table.

Key fields

The primary key is the set of fields that identifies one row; no two rows may have the same key. In the source of a table you mark a key field with the word key in front of it, and the key fields stand together at the top of the field list. The fields of the key are always not null: the cheat sheet states that this flag is always set for key fields. When a program inserts a row whose key already exists, the insert does not store it and sy-subrc is 4, which the lab example below shows. The Keyword Documentation says each dictionary table has a unique primary index; a secondary index and a foreign key to another table are covered on the next page of the section.

Fields of a table must have an elementary type: the cheat sheet notes that reference types, substructures and table types are not allowed as table fields. Structured content enters a table through an include, shown further down.

A table in source code

In ADT a table is plain text. The annotations at the top describe the table as a whole, and the fields follow in braces. The example defines the claim table of the running Expense claims example: a client field, the claim number as the key, the employee, a status code, the currency and the total, and the audit fields that come from a shared structure. The amount field names its currency field in the annotation @Semantics.amount.currencyCode, written as table name, a dot and field name, as in SAP’s own example. It requires an SAP system; not run here.

@EndUserText.label : 'Expense claim'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zexp_claim {
  key client    : abap.clnt not null;
  key claim_id  : abap.char(10) not null;
  employee_id   : abap.numc(8) not null;
  status        : abap.char(1) not null;
  currency_code : abap.cuky not null;
  @Semantics.amount.currencyCode : 'zexp_claim.currency_code'
  total_amount  : abap.curr(15,2) not null;
  include zexp_s_audit;
}

Reading it from the top: @EndUserText.label is the short description shown to people; the other four annotations are explained in the next sections. Each field line has a name, a colon and a built-in dictionary type such as abap.char(10) for ten characters or abap.curr(15,2) for a currency amount with two decimals; the data elements and domains of the previous page can be used in place of these built-in types. Every statement ends with a semicolon. The last line pulls the fields of a structure into the table.

The ADT user guide marks several of these annotations as mandatory when you create or edit a source-based table, among them the table category and the enhancement annotations, so keep them all in a new table.

Technical settings

The technical settings of a table describe how the database should store and handle it, not what it means. They are kept as a separate object, so they can be activated and transported on their own. The ADT guide lists them as follows.

  • The data class says in which area of the database the table is stored, and the size category says how many rows to expect, so that the database reserves enough space. A wrong guess costs space or later reorganisation, not correctness.

  • The storage type and load unit control how the table is kept on the database.

  • Buffering decides whether the application server keeps copies of rows in its own memory. The states are buffering not allowed, buffering switched on, and buffering allowed but switched off; when it is on you choose between single entries, generic key areas (and then the number of key fields) and the full table.

  • Log changes decides whether changes to the table rows are logged.

When you create a table in ADT its technical settings are created with default values, and the ADT guide says that to edit the data class, size category, buffering and storage type, and to create or edit indexes, you open the integrated SAP GUI. Buffering a table that changes often is a mistake: every change invalidates the buffered copies. Leave it off for a table such as the claim table until you have measured a read-mostly access pattern.

Delivery class and data maintenance

The delivery class controls what happens to the rows of the table during installation, upgrades, client copies and transports between systems. It is written @AbapCatalog.deliveryClass and has these values.

Value Meaning

#A

Application table for master data and transaction data, written by application programs. The default in ADT, and the right choice for the claim table.

#C

Customizing table with data entered by the customer only.

#L

Table used as a repository of temporary data; SAP delivers such tables empty.

#G

Customizing table where SAP may add data but not change or delete it; needs a customer namespace entry.

#E

System table in which customers can make entries; needs a customer namespace entry.

#S

System table delivered by SAP with predefined data, transported like repository objects.

#W

System table for administration data of a system, such as TFDIR, the directory of all function modules; usually delivered with entries from SAP.

The annotation @AbapCatalog.dataMaintenance says whether table content may be displayed and edited with the Data Browser (transaction SE16) and the table view maintenance (SM30 and SM31): #RESTRICTED (the default in ADT) lets SE16 display but not edit, #ALLOWED lets SE16 display and edit, #DISPLAY lets SE16 display only, and #NOT_ALLOWED blocks both. For a business table such as claims you choose #RESTRICTED so that nobody edits data around the application.

Structures

A structure is a data type made of components. Each component can be an elementary type, given by a data element or by a built-in type and length, another structure, or a table type, and a structure can be nested to any depth. Unlike a table a structure has no key and no technical settings, and it stores no data. You define one with DEFINE STRUCTURE. The audit structure below holds the two fields that every table of the example should carry. It requires an SAP system; not run here.

@EndUserText.label : 'Audit fields'
@AbapCatalog.enhancement.category : #EXTENSIBLE_CHARACTER_NUMERIC
define structure zexp_s_audit {
  created_by : abap.char(12);
  created_at : abap.dec(15,0);
}

Structures are used three ways. In an ABAP program they type a work area: DATA claim TYPE zexp_claim. works for a table and DATA audit TYPE zexp_s_audit. for a structure. They type the parameters of a method or function, and they are reused inside tables and other structures through include, as the next section shows. Because a dictionary table is also a structure type, you rarely need a separate structure just to describe the table row.

Includes

An include copies the components of another structure into the structure or table that contains it, as if you had typed them there. The last line of the table above, include zexp_s_audit;, brings created_by and created_at into zexp_claim as two ordinary columns; the database has no trace of the structure. One structure thereby serves many tables, and a change to it reaches all of them on activation. The cheat sheet shows that a suffix can be assigned to the components of an included structure, so that the same structure can be included twice without name clashes: include zexp_s_audit with suffix _in;.

Enhancement category and append structures

SAP delivers tables and structures that customers and partners need to extend with their own fields, and customers do the same with their own objects. An append structure adds components to an existing structure or table without changing the original object. It is a separate development object that starts with the keywords EXTEND TYPE, names the base structure, then WITH and its own name. The ADT user guide shows the form, and the classic documentation adds the rules that matter in practice: the append structure can be created only on the basis of an existing structure, its fields must lie in the customer namespace (names starting with ZZ or YY in the SE11 screens), it must be flat, and activating it adds the fields to the table in the database.

@EndUserText.label : 'Audit fields: partner extension'
@AbapCatalog.enhancement.category : #EXTENSIBLE_CHARACTER
extend type zexp_s_audit with zexp_s_audit_ext {
  zz_changed_by : abap.char(12);
}

This listing requires an SAP system; not run here. Whether the base object may be extended at all is the job of the enhancement category, set with the annotation @AbapCatalog.enhancement.category. It predefines the warnings the system gives when your change would break an extension. The values are these.

Value Meaning

#NOT_EXTENSIBLE

The structure or table cannot be enhanced. The default for new structures created in ADT.

#EXTENSIBLE_CHARACTER

All components and all enhancements must be character-like and flat.

#EXTENSIBLE_CHARACTER_NUMERIC

All components and enhancements must be flat, which allows numeric fields too.

#EXTENSIBLE_ANY

Components and enhancements can have any data type.

#NOT_CLASSIFIED

No enhancement category; offered only for structures that already exist, not for new ones.

The three annotations @AbapCatalog.enhancement.fieldSuffix, @AbapCatalog.enhancement.quotaMaximumBytes and @AbapCatalog.enhancement.quotaMaximumFields belong to the same family: a three-character suffix for the fields of appends (suffixes beginning with Y or Z are reserved for partners), and the bytes and fields that SAP reserves for customers, recommended at 1,000 to 3,500 bytes per structure. For your own tables the safe default is #NOT_EXTENSIBLE, as in the claim table. Choose a more open category only for a structure that you really expect others to extend. Some pages of the ADT guide spell the annotation @AbapCatalog.enhancementCategory, and one of them describes #NOT_EXTENSIBLE with different wording; the current Enhancement Annotations page and the SAP cheat sheets use the dotted spelling shown here and describe the category as not enhanceable.

Whether an SAP object may be extended at all depends on its enhancement category and, in ABAP Cloud, on what SAP has released for use; the page ABAP Language Versions and Released APIs explains the released-object idea.

Using the table: an example that runs

A table definition is only text until it is used. The example below uses a small cut of the claim table that exists in the local playground: claim number as the key, a status and an integer amount. The playground builds an in-memory database table from the table definition file, so the ABAP program can declare a work area typed with the table, insert a row and read it back. The third statement inserts the same key a second time: the key is unique, so nothing is stored and sy-subrc is 4. It runs in the local playground and prints the lines shown below.

REPORT zexp_show.

DATA claim TYPE zexp_claim.

claim-claim_id = 'C-1001'.
claim-status   = 'N'.
claim-amount   = 12050.
INSERT zexp_claim FROM @claim.
WRITE / |insert rc { sy-subrc }|.

CLEAR claim.
SELECT SINGLE * FROM zexp_claim WHERE claim_id = 'C-1001' INTO @claim.
WRITE / |read rc { sy-subrc }: { claim-claim_id } { claim-status } { claim-amount }|.

INSERT zexp_claim FROM @claim.
WRITE / |second insert rc { sy-subrc }|.
insert rc 0
read rc 0: C-1001 N 12050
second insert rc 4

The playground has no client field, no technical settings and no enhancement category: it creates the table from the file and ignores what a real ABAP Dictionary adds. What the example shows is the part that matches a real system: the table name is a type, INSERT writes a row from a work area, SELECT SINGLE reads one by key, and the unique key rejects a duplicate.

Older material you may meet

  • Books and older programs create tables on the SE11 screen, field by field, and set the delivery class, the data class, the size category and the buffering on the screens of the Technical Settings. The result is the same dictionary object that the source above describes; only the editor differs.

  • Older tables carry the client field under the name MANDT and types such as CHAR and CURR written in capitals. In source form these are abap.clnt, abap.char(n) and abap.curr(n,m).

  • Pool and cluster tables, described above, appear only in older data models.

Summary

  • A DDIC database table is a dictionary description from which the system creates a real table when it is activated; it is also a structure type you can use to declare variables, and ABAP SQL reads and writes its rows.

  • A new table is transparent, with a client field as the first key field, further key fields marked key and not null, and fields of elementary type only.

  • The technical settings (data class, size category, buffering) and the annotations for delivery class, data maintenance and enhancement category must be chosen on purpose; for business data use delivery class A.

  • A structure has components but no rows and no key; an include copies its components into a table, and an append structure adds components later without changing the original object, as far as the enhancement category allows.

  • Pool and cluster tables are legacy and cannot be created in ADT; an older system may still hold them.