Vous êtes sur la page 1sur 10

ABAP Tables, Data Elements and Domains

Prepared by J Kreie
New Mexico State University
ABAP Tables, Data Elements and Domains
This lesson covers creation of ABAP Dictionary definitions for domains and data elements and using these in
defining the fields in a new table. Later, you will create a program to display the table contents and a program to
add data to the table.
Domains and Data Elements
Lets start by taking a look at some metadata in the ABAP Dictionary. Metadata is data about the data in a
database. For example, the metadata about a table would be the table name, the names of fields in the table,
the attributes of each fielddata type, field size, and so on.
Open the ABAP Dictionary (Tools....ABAP Workbench
DevelopmentABAP Dictionary [SE11]). View the table used in
the previous lesson from the flights database: s
STRAVELAG

Click the Display button and youll see the


metadata about STRAVELAGthe column
names, data types, field lengths, and more.

Use the Back button


to return to the
initial screen for the ABAP Dictionary.

Now, well look at a domain. Select the radio button next


to Domain and open the value search for Domain (click
the box and hit F4). Type employee between asterisks.

From the list of domains shown, find and select P06_GENDER.


Back in the ABAP Dictionary: Initial Screen click the Display button.
Page 1 of 10

ABAP Tables, Data Elements and Domains


Prepared by J Kreie
New Mexico State University

The Display Domain screen shows that this


domain is a CHAR data type with a field size
of 1 character.

Click the Properties tab and you see that this


domain was defined for French in a package
called PB06.

Click the Value Range tab and you see the three
possible entries for employee gender: M, F, and
N.

Return to the ABAP Dictionary: Initial Screen and start the value
search again. Search for *country code* in the Short
Description field.
Select the domain INTCA3 and display this domain. INTCA3 is a 3-character string (Definition tab) used in the
SZAD package (Properties tab). This 3-character definition provides for space to store codes assigned by the
International Standards Organization (ISO) for each country (see http://en.wikipedia.org/wiki/ISO_31661#Current_codes). For example, the 3-character code for Albania is ALB and the code for Belize is BLZ.
Now weve seen a few examples of domains in the ABAP Dictionary but what is a domain exactly? In relational
database terms, a domain is the definition of a data type. The domain specifies the type of data (character,
numeric, etc.) and may specify a value range, such as the gender example above. As a programmer, you can
Page 2 of 10

ABAP Tables, Data Elements and Domains


Prepared by J Kreie
New Mexico State University
think of a domain as analogous to a class. To carry this analogy further, you could think of the domain as the
class, the data element as the object based on that class. (See C. J. Dates articles or books for more about
the role of domains in relational databases.) A data element is based on a domain, so it has the same data type
and field size as the domain, but the data elements adds context-specific or situation-specific information. So,
the domain is the generic, standard data type definition and the data element customizes this for a specific
situation.
Look at an example of data element. With the domain INTCA3 still showing in the Dictionary: Display Domain
screen, click the where-used icon
checkmark.

. Accept the default settings in the next dialog box and click the
You see some data elements that
use the INTCA3 domain.

Using forward navigation, double-click the


PTRV_CCC_PURCHASE_COUNTRY and view
the details about this data element.
The Data Type tab shows that this data element
uses the domain INTCA3 and it is a 3-character
string.

The Attributes tab shows what package this


data element was created for and in what
language.

Page 3 of 10

ABAP Tables, Data Elements and Domains


Prepared by J Kreie
New Mexico State University
The Field Label tab shows how SAP
determines what text to display with this data
element depending on the space available in a
screen.
The field labels provide meaningful, situationspecific text for the field in a table that is
assigned this data element.
You can also create features for a data
element, such as help documentation. If you
do this, then when a user selects a field based
on this data element then hits the F1 key, the help text you created will appear.
Another example of a domain and data elements would be to create a mail code (zip code) domain. Two data
elementsmailing address code and shipping address codewould reference the same domain but the labels,
the situation-specific text would be set for each data element.
Create domains
A little later in this lesson you will build a few tables. Below is a model of two tables you will build. These tables
have no practical purpose in SAP but building them will show you how to construct tables and build the primary
key-foreign key relationship.

In preparation for building the tables first you will create domains and data elements for the type of data your
table will store. For the purpose of learning how to create domains and data elements, you will not use existing
domains in the ABAP Dictionary though youll do so a bit later.
Return to the ABAP Dictionary initial screen (SE11). Check the
Domain radio button and type a domain name using this
template: Z_$$$$_level. Click the Create button.
Enter the short description, data type and number of characters,
as shown here. Save the domain to your lessons package and
transport request.
Check and activate this domain.

Repeat this process in order to create the following domains. Save and activate each one.
Page 4 of 10

ABAP Tables, Data Elements and Domains


Prepared by J Kreie
New Mexico State University
Domain Name
Z_$$$$_level_desc
Z_$$$$_ID
Z_$$$$_fname
Z_$$$$_lname
Z_$$$$_edu_major

Data Type
CHAR
NUMC *
CHAR
CHAR
CHAR

No. Char
12
5
12
15
18

Short Description
Education level description
Identification code
First name
Last name
Education major

* The NUMC datatype is for character data that are numeric characters only (like a zip code).
Use the ABAP Dictionary initial screen to retrieve and display the
domain you created for education major. Select the Value Range
tab. Enter the text shown here.
Save and activate this domain with these changes.

Create data elements


Open the Object Navigator and open your
lessons package if it is not already displayed.
Package name and select Create
Dictionary Object Data Element. Type in a
data element name using this template: Z_$$$
$_edu_lvl.
Enter Education Level as the short description
and enter or find the domain you created for
this data element.
Select the Field Label tab. Enter the text shown here.
Click the checkmark and the label lengths will be set to
default lengths. You can, however, enter the lengths you
prefer. Save this data element but dont exit. Now, youll
create some user documentation for this data element.

Page 5 of 10

ABAP Tables, Data Elements and Domains


Prepared by J Kreie
New Mexico State University

Click the Documentation button


.
If your computer has Microsoft Word installed a
template will open that looks similar to the
example shown here but it will be in Word.
Enter the text indicated in the example.
Save and go back with the Back button.
Activate this data element.

Create the remaining data elements shown below. Be sure to add field labels. You do not have to add the
documentation for each element but you can do so, if you wish.
Save and activate these data elements.
Data Element Name
Z_$$$$_level_desc
Z_$$$$_StudentID
Z_$$$$_firstname
Z_$$$$_lastname
Z_$$$$_educ_major

Short Description
Description of education level
Student Identification Code
Students first name
Students last name
Students major

In the Object Navigator, notice that the domains and data elements
created are now listed in your package. Note, though, that the
example list shown here has data elements in a different color.
This is very helpful! The first two data elements listededucation
major and education levelare not active. They have either
never been activated or theyve been modified and saved but not
activated. Its easy to forget to activate something.

Domain
Z_$$$$_level_desc
Z_$$$$_ID
Z_$$$$_fname
Z_$$$$_lname
Z_$$$$_edu_major

you

re-

If these were your data elements you could double-click each


name, which opens it, and activate each element. Youll find this
feature in the ABAP Workbench helpful in identifying parts of your
development project that havent been activated.

Page 6 of 10

ABAP Tables, Data Elements and Domains


Prepared by J Kreie
New Mexico State University
Create table
Now you will create two tables that use the domains and data elements youve created. In the Object Navigator
use the context menu for the Dictionary Objects in your package. Select Create Database Table. (An
alternative way to create these tables would be to go straight to the Data Dictionary [SE11]). Use this naming
template to name your table: Z$$$$_EduLevel. Note that there is no underscore after Z. The Delivery and
Maintenance tab is automatically selected. Enter the short description Education Levels. Use the value search
for Delivery Class and select A (Master and transaction data). Change the Data Browser/Table View Maint.
setting to Display/Maintenance Allowed.

Switch to the Fields tab. Enter


the field names shown here and
check the two columns to the
right of the field Lvl (columns
key and initial value). Type
your data elements names in the
Data Element column. You can
see these names by expanding
the list in the left pane.

Click the checkmark and the


metadata about each data
element will appear (data type,
length, and description.).

Use the SAP menu bar to select: Extras Enhancement Category. Youll
probably get a message that you need to select an enhancement category;
proceed by clicking the checkmark. Click the checkmark to accept the default
setting: Can be enhanced.
Save the table to your transport package. Do not worry if you get a message
about tables being client specific. The client specific message occurs
because you should always include a field in any table you build for the SAP
Page 7 of 10

ABAP Tables, Data Elements and Domains


Prepared by J Kreie
New Mexico State University
client number (called mandt in German), if the table will be used in a real, working environment. We dont need
to worry about that for this lesson.
Click the Technical Settings button
. Under the Logical storage parameters heading for Data
class type or select APPL0 for master data, transparent tables. For Size
category type 0 (0 to 21,000 records). We do not expect this table to have
many rows of data. Save your changes and use the back button to return
to
the Maintain Table screen.
Save, check and activate the table.
Create another table called Z$$$$_Student. Enter the short description Student Information. Use the value
search for Delivery Class and select A (Master and transaction data) and set Data Browser/Table View Maint.
to Display/Maintenance Allowed.
Select the Fields tab and create the
fields shown here and for each field type
the appropriate data element you
created.

Remember data model these two tables are based on? This model
shows that the student table has a foreign key field related to the
education level table. Now, youll designate the foreign key in the
student table. Click the STUDENTLVL field to select it then click the
foreign key icon
. For the Short Text enter Students education
level. For the Check Table, use the value search icon to locate
and select the EduLevel table you created.
Next, click the Generate proposal icon
. ABAP Workbench will look at the metadata the
EduLevel table and retrieve the name of the primary key field. Click the checkmark.
Set the enhancement category for this table through the SAP menu bar: Extras Enhancement Category.
Select Can be enhanced and click the checkmark.
Click the Technical Settings button. Set the Data class for APPL0 (Master data, transparent tables). Set the
Size category for 1. Save these settings and return to the table screen.
Save, check and activate this table. Again, dont worry about the client specific warning.
In the next lesson youll create programs to add data to your tables and to display the data.

Page 8 of 10

ABAP Tables, Data Elements and Domains


Prepared by J Kreie
New Mexico State University

Practice
Create two tables based on the following data model. Create the necessary domains and data elements and
use these in the tables. The registration table has a date field, which you havent defined before. Use the DATS
data type with a size of 8.

Terms to Know
ABAP Dictionary..................................................................................................................................................... 1
data element........................................................................................................................................................... 2
domain.................................................................................................................................................................... 2
metadata................................................................................................................................................................. 1

Page 9 of 10

References
An Introduction to Database Management Systems. C. J. Date, Addison-Wesley, 8th edition, 2003.
Database in Depth: Relational Theory for Practitioners. C. J. Date, OReilly Media, 2005.
ABAP Basics. Gnther Frber and Julia Kirchner, SAP Press - Galileo Press, 2007.
Discover ABAP. Karl-Heins Khnhauser, SAP Press, 2007.
ABAP Objects: An Introduction to Programming SAP Applications. Horst Keller and Sascha Kruger, SAP Press,
2002.

Vous aimerez peut-être aussi