Domains and Data Elements
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Every field in a business application has a shape and a meaning. The shape is technical: how many characters, whether it holds digits or text. The meaning is human: "claim status", with a label a person can read on a screen. The ABAP Dictionary keeps these two things apart so that you can define a shape once, give it many meanings, and change it in one place. The objects that do this are the domain, which holds the shape and the list of allowed values, and the data element, which holds the meaning. After reading this page you can explain what each one stores, create both in ABAP Development Tools (ADT), describe what a value range does and what it does not do, and tell when a modern CDS type should replace them. It is written against Standard ABAP release 8.16 and ABAP for Cloud Development release 9.20 (2608). Domains and data elements exist in classic Standard ABAP, on premise and in the Public Edition alike, and ABAP Cloud projects may still create and use them. Several of their semantic properties only serve classic screens (dynpros), and for new work with RAP the CDS successors described near the end are the recommended choice.
Before you read
-
Data Types and Data Objects: elementary types,
TYPESandDATA. -
Classic Tools: SE80, SE38, SE11, SE37 and SE16: SE11 is the classic tool in which the objects of this page are maintained.
-
ABAP Development Tools in Eclipse: the editors used in the example.
-
Currencies, Units and Conversions: the
ALPHAconversion exit is shown there in a program. -
Database tables and structures, foreign keys, and views and search helps have pages of their own that come later in this section; this page only mentions them.
Key terms
-
ABAP Dictionary: the central, transportable store of type definitions such as domains, data elements, structures and database tables.
-
Domain: a Dictionary object that describes the technical shape of an elementary value and, optionally, its allowed values.
-
Data element: a Dictionary object that gives an elementary value (or a reference) its type and its meaning, including field labels.
-
Fixed values: the list of single values or intervals that a domain names as the allowed ones, each with a short text.
-
Conversion exit: a pair of routines that translate a value between the form a person types and the form that is stored.
-
Field label: the short, medium, long and heading texts of a data element that screens use as a caption or column title.
-
Search help: a Dictionary object that builds the list of values offered when a person asks for input help on a field.
One field, two levels
Think of the status of an expense claim. As a shape it is "one character". As a meaning it is "the status of a claim, captioned Status on a screen, and one of Draft, Submitted, Approved or Rejected". The shape could be reused by dozens of other fields (a flag, a priority code) and the meaning belongs to this one concept. The ABAP Dictionary models exactly that split.
-
The domain is the lower level. It describes only an elementary type: a built-in Dictionary type, a length and, when needed, decimal places, plus semantic extras such as the output length, a value range and a conversion exit. Many data elements may point to the same domain.
-
The data element is the upper level. It either takes its technical properties from a domain or states them directly, and it adds the meaning: the field labels, the documentation, an optional search help.
-
A table field, a structure component or an ABAP variable is then typed with the data element.
SAP calls the idea of building a type from a domain and a data element the two-level domain concept. The two levels are optional in one direction: a data element may define its type directly and have no domain at all.
A domain cannot be used on its own as a type. It describes properties of an elementary type, but it is not a data type
itself, so TYPE zexp_status in a program always resolves to the data element, never to the domain, and a domain cannot
be used in Dictionary objects other than data elements. A domain and a data element may have the same name, because they
live in different name spaces; the example below uses this.
Domains
A domain has technical and semantic properties.
Technical properties. Exactly three things: the built-in Dictionary type, the length, and optionally the number of decimal places. The built-in Dictionary types are the foundation of every elementary component in the Dictionary. When a type is used in an ABAP program, the Dictionary type is mapped to an ABAP type. A selection:
| Dictionary type | Meaning | ABAP type |
|---|---|---|
|
Character string of fixed length, at most 1333 places for table fields |
|
|
Numeric text: digits only, stored as characters |
|
|
4-byte integer |
|
|
Packed number, up to 31 places |
|
|
Date and time in the internal format of the database |
|
|
Date and time as the text formats |
|
|
Client |
|
|
Character string, 1 to 1333 places |
|
Semantic properties. A short text is required. The rest is optional:
-
the output length, which overrides the length a screen would otherwise reserve for the type;
-
the conversion exit, described below;
-
the value range, made of fixed values and intervals, described in the next section;
-
the value table, a Dictionary table that serves as the default check table when a table field that uses a data element of this domain takes part in a foreign key. Naming a value table does not by itself trigger any check.
-
documentation, and for some types an output style or a time format.
Two guidelines from the documentation are worth following. Do not create redundant domains inside an application component
or package: domains that carry only technical properties (the documentation names CHAR255) belong in a central package
and are reused. And because a change to a domain affects every data element that uses it, foreign keys that involve those
fields can become inconsistent and need adjusting, so change shared domains with care.
Value ranges and fixed values
A value range lists the values a field is meant to hold. It consists of fixed values (single values), intervals (a lower
and an upper limit), or any mixture of both, and each entry can carry a short text that is shown in an input help. Value
ranges can be defined for domains of the built-in types CHAR, NUMC, DEC, INT1, INT2, INT4 and INT8. For
CHAR the fixed value is limited to ten characters, and for the numeric types the values are positive integers including
0 that lie inside the range the technical properties allow. SAP-delivered fixed values can be extended by customers and
partners with fixed value appends.
What a value range does and does not do deserves a plain statement, because newcomers often get it wrong.
-
It serves screens: on a classic dynpro field that refers to the domain (through a data element), only the listed values are accepted, and the list can be shown as input help.
-
It is ignored by ABAP statements: the content of a data object declared in a program, or of a database table field typed with such a data element, is not checked against the value range. Assigning
'X'to a status variable whose domain lists onlyD,S,AandRworks without an error or a runtime exception. -
Fixed values can be used for value helps in the context of CDS views, and in DDIC-based CDS views they can be written as special literals, which is marked obsolete.
If your program needs the check, write it yourself, or use a type that enforces values, such as a CDS enumerated type (see below).
The following program shows the second point. It uses the domain and the data element of the running example. It runs in the local playground, where the domain and the data element are stored as the two abapGit files shown right after it; the playground does not look at the fixed values, which is the behaviour of ABAP statements described above. The program prints the length of the type and then the status after two assignments, the second one outside the value range.
REPORT zexp_status_demo.
DATA status TYPE zexp_status.
DESCRIBE FIELD status LENGTH DATA(len) IN CHARACTER MODE.
WRITE / |length of ZEXP_STATUS: { len }|.
status = 'A'.
WRITE / |status after assigning A: { status }|.
status = 'X'.
WRITE / |status after assigning X: { status }|.
The output, run in the local playground, is:
length of ZEXP_STATUS: 1
status after assigning A: A
status after assigning X: X
The playground reads Dictionary objects in the abapGit file layout, a community format. The files for this example hold the same properties that the ADT editors show, and they are given for the playground only; in a real system you create the objects in ADT or SE11 and never write these files by hand.
<!-- src/zexp_status.doma.xml (abridged: the other two fixed values follow the same pattern) -->
<DD01V>
<DOMNAME>ZEXP_STATUS</DOMNAME>
<DATATYPE>CHAR</DATATYPE>
<LENG>000001</LENG>
<OUTPUTLEN>000001</OUTPUTLEN>
<VALEXI>X</VALEXI>
<DDTEXT>Status of an expense claim</DDTEXT>
</DD01V>
<DD07V_TAB>
<DD07V><VALPOS>0001</VALPOS><DOMVALUE_L>D</DOMVALUE_L><DDTEXT>Draft</DDTEXT></DD07V>
<DD07V><VALPOS>0002</VALPOS><DOMVALUE_L>S</DOMVALUE_L><DDTEXT>Submitted</DDTEXT></DD07V>
</DD07V_TAB>
<!-- src/zexp_status.dtel.xml (abridged) -->
<DD04V>
<ROLLNAME>ZEXP_STATUS</ROLLNAME>
<DOMNAME>ZEXP_STATUS</DOMNAME>
<DDTEXT>Claim status</DDTEXT>
<SCRTEXT_S>Status</SCRTEXT_S>
<SCRTEXT_M>Claim status</SCRTEXT_M>
<SCRTEXT_L>Claim status</SCRTEXT_L>
</DD04V>
Conversion exits
Some values are stored in one form and shown in another. A claim number may be stored as 0000000042 and typed and read
as 42. A conversion exit is the Dictionary’s answer: a five-character name that you set as a semantic property of a
domain. It is implemented by two function modules named CONVERSION_EXIT_<name>_INPUT (display form to stored form) and
CONVERSION_EXIT_<name>_OUTPUT (stored form to display form). Once a domain carries the exit, it runs automatically in
these places:
-
when a dynpro field defined with a reference to the domain passes input to ABAP and when ABAP passes output to it;
-
when a data object typed with such a domain is formatted with
WRITEorWRITE ... TO, where the output routine runs by default and the additionUSING NO EDIT MASKswitches it off. If an exit runs, the other formatting options are ignored.
In ADT the Domain editor lets you choose the exit under Output Characteristics: the Conversion Routine link lists the
conversion function modules, and the five-character ID from the chosen module name is entered into the field. A conversion
exit is not applied to values you move with plain assignments in program code, so in code you ask for the conversion
explicitly, for example with the ALPHA option of a string template, which
Currencies, Units and Conversions shows in a running
program. Writing your own exit needs two function modules in the same function pool with generic INPUT and OUTPUT
parameters; this belongs to classic Standard ABAP and a page of this section on function modules and classic programming
is the place to learn it.
Data elements
A data element defines either an elementary type or a reference type, and describes the meaning of whatever is typed with it.
Technical properties. An elementary data element has a built-in Dictionary type, a length and, if needed, decimal
places, either defined in the data element directly or inherited from a domain. A reference data element describes a data
reference variable (typed with the generic type data, a Dictionary type or a built-in type) or an object reference
variable (typed with object, a global class or a global interface). Reference types can be used for typing in programs,
but not for fields of database tables or for elements of CDS entities.
Semantic properties. These matter mostly when the data element types a field on a screen:
-
Field labels: the short, medium and long labels and the heading. Screens use them as captions and column titles. You set a maximum length for each, which applies to all languages. The texts are connected to the translation tools like every AS ABAP text. SAP’s cheat sheet adds that the medium label is exposed to OData.
-
Documentation and its status, which is read as the F1 help of every screen field that refers to the data element.
-
Search help: an elementary data element can be assigned a search help and a parameter of it. A reference data element cannot.
-
SPA/GPA parameter, flag for input history and flags for bidirectional fonts, all of them classic screen features.
-
Default component name, a naming suggestion for structure components typed with the data element, and the flag for change documents.
An important detail: an ABAP data object declared with TYPE <data element> takes the technical properties and ignores
the semantic ones. A label or search help does not change how a program variable behaves; they only act where a screen,
an input help or a framework reads the Dictionary. Some of the semantic properties apply only to classic UIs and cannot be
specified in ABAP for Cloud Development.
Example: the ZEXP_STATUS domain
The Expense claims example needs a status for a claim. The goal is a domain ZEXP_STATUS with the four fixed values and a
data element of the same name that fields and variables can use. The names start with Z, the customer namespace, so
they cannot clash with SAP objects. The steps use ADT, the tool recommended for new work; SE11 offers the same properties
in a screen form. They require an SAP system; not run here.
Create the domain.
-
In the Project Explorer select the package, open the context menu and choose New, Other, Dictionary, then Domain.
-
Enter the name
ZEXP_STATUSand the description "Status of an expense claim", choose Next, assign a transport request and choose Finish. The inactive domain is created and the Domain editor opens. -
In the Format section enter the data type
CHARand the length1. -
In Output Characteristics enter the output length
1. No conversion routine is needed: the values are already in display form. -
In Fixed Values add
Dwith the description Draft,SSubmitted,AApproved andRRejected. -
Save, then activate.
Create the data element.
-
In the same package choose New, Other, Dictionary, then Data Element, with the name
ZEXP_STATUSand the description "Claim status". -
In the Data Type Information choose the category Domain and enter
ZEXP_STATUSas the type name. -
In Field Labels enter Status (short), Claim status (medium), Claim status (long) and Status (heading), each with a maximum length at least as long as the text.
-
Save, then activate.
Once both objects are active they can be used by all other repository objects, subject to the package concept. Until you activate them, programs and other objects keep working with the previous active version, and a Dictionary object can be deleted only after everything that uses it has been removed.
A program uses the data element like any other type. The same statements run in the local playground, as shown above.
TYPES ty_status TYPE zexp_status.
DATA status TYPE zexp_status VALUE 'D'.
" Which status text belongs to which value is stored in the domain, not in this program.
IF status = 'D'.
WRITE / 'Claim is still a draft'.
ENDIF.
Source: ADT User Guide: Creating Domains, ADT User Guide: Creating Data Elements, ADT User Guide: Editing Data Elements
The status column of ZEXP_CLAIM is typed with this data element when the table is defined on the page about database tables and structures; from then on the claim table, the screens and the classes that use the status all share one
definition.
CDS types as the modern successors
ABAP CDS can define the same ideas in source code instead of forms. A CDS simple type is a successor of the domain and the data element, and a CDS enumerated type is the successor of a domain with fixed values.
-
CDS simple type (
define type ... : ...) defines an elementary type. It can be enriched with CDS annotations, and frameworks such as RAP read this metadata, which gives OData and Fiori scenarios the semantic information a data element carries. Simple types can be nested, which gives more reuse than domains and data elements. A simple type cannot be used to type a DDIC data element or a DDIC view. -
CDS enumerated type (
define type ... enum) defines a base type and a set of named constants. It does check the value: the values that may be passed to CDS elements or parameters typed with it are restricted. In ABAP, an enumerated structure with the name of the type is declared implicitly, and its components are the constants. SAP states that CDS enumerated types currently cannot be used in OData scenarios or in Fiori applications built with RAP.
The status of the example as a CDS enumerated type would look as follows. One constant must be the initial one, and the base type is a built-in type. This requires an SAP system; not run here.
@EndUserText.label: 'Status of an expense claim'
define type zexp_status_enum : abap.char(1) enum
{
draft = initial;
submitted = 'S';
approved = 'A';
rejected = 'R';
}
Source: ABAP Keyword Documentation: ABAP CDS - Enumerated Types, ABAP Keyword Documentation: ABAP CDS - Simple Types, ABAP cheat sheet: ABAP Dictionary
The table sums up when to use which.
| You need | Domain and data element | CDS type |
|---|---|---|
A shape reused by many fields |
Domain |
CDS simple type |
Field labels for screens and OData |
Data element |
Annotations on a CDS simple type |
A checked list of allowed values |
Fixed values (screens and input help only) |
CDS enumerated type |
A type for a database table field or a Dictionary structure |
Data element |
Not possible: a CDS type cannot type DDIC objects |
A type for a RAP business object or CDS view element |
Possible |
Preferred |
For tables and structures that exist in the Dictionary you keep using data elements; the CDS types serve the CDS-and-RAP side. Both live side by side in the same system.
Older material you may meet
Books and code from before the ABAP Cloud era describe the Dictionary through the SAP GUI screens of SE11, with a Domain tab, a Value Range tab and screen-based forms. The concepts are the same, but four habits have changed.
-
Value ranges as validation. Older material presents fixed values as a data check. They check dynpro input only; ABAP statements and database writes ignore them, and modern developments check in code or with a CDS enumerated type.
-
Where objects are made. The older route is SE11; ADT offers form-based editors for domains and data elements. Both are maintained in the same Dictionary and the objects are the same.
-
Classic semantic properties. Search help assignment, SPA/GPA parameters, input history and bidirectional flags exist for classic dynpros. They are explained in older books at length. In new RAP applications, labels come from CDS annotations and value helps from CDS value help definitions, so you will rarely set them.
-
Date and time types. Older tables use
DATSandTIMS. The documentation prefersDATNandTIMNfor new work, becauseDATSandTIMSneed a conversion to the actual date and time types.
Common mistakes
-
Assuming the value range is enforced in the program or on the database. It is not; it affects dynpro input and input help.
-
Changing a widely used domain. Every data element and every field that uses it is affected, and foreign keys can become inconsistent.
-
Trying to write
TYPE zexp_statusand expecting the domain. The type is the data element; a domain is not a data type. -
Forgetting to activate. Other objects keep using the previous active version until the new one is activated, so a change that you saved has no effect yet.
-
Creating a domain per field. A domain that only repeats a type is redundant, so reuse a central one such as
CHAR255.
Summary
-
The ABAP Dictionary describes an elementary field in two levels: the domain holds the technical shape (built-in type, length, decimals) and semantic extras, the data element holds the meaning and the field labels.
-
A domain can carry fixed values, intervals, a value table and a conversion exit; a data element can carry field labels, documentation and a search help. A domain cannot be used as a type, only through a data element.
-
A value range acts on dynpro input and input help. ABAP statements and database fields do not check it.
-
A conversion exit is a pair of function modules named
CONVERSION_EXIT_<name>_INPUTand_OUTPUTthat runs on screens and inWRITE, not in plain assignments. -
In ADT you create both objects with form-based editors and then activate them. For new RAP work, CDS simple types and CDS enumerated types are the successors, but they cannot type DDIC objects.
-
The listing that assigns a value outside the range ran in the local playground. The ADT steps and the CDS enumerated type require an SAP system and were not run here.
References
-
ABAP Keyword Documentation: DDIC - Technical Properties of Domains
-
ABAP Keyword Documentation: DDIC - Semantic Properties of Domains
-
ABAP Keyword Documentation: DDIC - Technical Properties of Data Elements
-
ABAP Keyword Documentation: DDIC - Semantic Properties of Data Elements
-
ABAP Keyword Documentation: DDIC - Overview of All Built-In Dictionary Types
-
ADT User Guide: Working with Classic Objects in ABAP Dictionary