Data Elements vs. Domains

Lets start with explaining what are these two terms needed for.

When we are defining database tables within SAP, each and every field needs to contain specific type.

Lets say that we create a database table called Store. Along with other fields the store also needs to contain information when it is opened and closed.

In this case, let’s assume that 2 fields I have just described are called OPENED_AT and CLOSED_AT.

In order to store such information in that field and display its type in a humanly readable way, e.g. OPENED_AT field contains e.g. “Store Opened At” label, we need to define data element containing such information.

Both fields need to handle data in time format containing the information about time availability of the store – this is the domain.

Notice: Domain does not need to be created for each and every Data Element, because Data Element itself handles also technical information of its type. There are 2 common cases when we usually create domains for data elements (mentioned below in the article)

Data Element

Data Elements are semantic information about fields or components. They also contain technical attributes of the fields or components. The technical attributes of Data elements can be described either with Predefined Type or a reusable Domain.

A Data Element can be referenced in ABAP programs as TYPE. In the Declarations section, we can define variables in ABAP programs that take on attributes of a Data Element.

2 common ways to create Data Element

1. Transaction SE11

This is the standard way of creating Data Elements.

Choose “Data type” radio button, enter Data Element name, e.g. ZAS_DDIC_OPENED_AT, and click Create button.

Note: The data element’s name starts with ZAS. Why? Every customer object name in SAP must start with Z or Y. In ABAP Academy, we add the developer’s initial name right after Z or Y. AS is my initial name. All objects that I created to start with ZAS.

In “Data Type” tab, define technical detail of Data Element.

Right here you have 2 options:

  • If you have already defined a domain you can use it right here to define its data type (as shown in the image below).
  • Choose “Predefined Type” where you can manually define that you will use time type “TIMS” with length 6.

Notice: Both ways will technically work. Later in this article we will talk about the cases when we commonly use domains.

In “Field Label” tab, fill in all labels of the Data Element. By this we provide humanly readable way to understand users what type of data this data element contain.

Check syntax (CTRL +F2) and activate (CTRL+F3).

Data Element is created.

2. Transaction SE80

We as developers often look for the easiest and fastest ways on how to develop our solutions. Such a way of creating Data Elements is by using transaction SE80.

More about it in the article: How to Create Database a Database Table.

Domain

Domains are a technical description which can be used by more than one data elements with similar characteristics. Domain is assigned to Data Element.  Fields that refer to the same domain are also changed when the domain is changed.

When To Create Domain?

There are two cases when we usually create domains.

Case 1: When creating fields of repeating data types

This is exactly the case of showing the difference between Data Elements and Domains from the beginning of this article.

Fields OPENED_AT and CLOSED_AT use exactly the same type of time. For this case, we create 2 different Data Elements for each field and 1 common domain.

How to create a domain?

In ABAP Academy we look for the fastest and most effective ways on how to create our software. That’s why I will show you how we create domains.

To create a Domain, go to the Data Element which you want to create domain for.

Choose Domain radio button and type new domain name: ZAS_DDIC_TIME_AVAILABILITY. Then double click on the domain name to define technical detail.

Type the Short Description, Data Type and length.

Check syntax (CTRL+F2) and activate(CTRL+F3)

Domain is created.

Case 2: To restrict the value of the field

In “Value Range” tab, there are 3 restrictions that can be used :

“Single Vals” to restrict the value of the field into limited choices. For example to restrict the city into 3 cities possible.

“Interval” restriction to limit the value of the field into certain interval, between lower limit and upper limit.

“Value Table” restriction used when the value of the field based on table look up / reference table.

Let us know your opinion

  • Was this article useful for you?
  • Do you want to know more about Data Elements and Domains?
  • .. or you just liked it?

Let us know in the comments ;)

Comments

Add a comment

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

 

Your personal information will be exclusively used for processing current comment only. Personal data protection policy