Sie sind auf Seite 1von 14

What is ABAP Data Dictionary?

SQL can be divided into following 2 parts.

DML Data Manipulation Language


DDL Data Definition Language
DML part consists of query and update commands like SELECT, UPDATE,

DELETE, INSERT

etc. ABAP programs handle DML part of SQL.


DDL part consist of commands like CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE INDEX
etc. ABAP Dictionary handles DDL part of SQL.
So ABAP Dictionary is used to create and manage data definitions (metadata). ABAP Dictionary is used to
create Tables, Data Elements, Domains, Views, Lock Objects etc.

What are Data Elements and Domains?


While creating a table in data dictionary each table field is assigned to a data element. Each data element is in
turn assigned to a domain.

Domain describes the technical attributes such as data type and length of a table field.
Data Element gives the field labels and documentation for the table field.
Consider the following code. PARAMETERS is the keyword to create input fields.
PARAMETERS: p_matnr TYPE matnr.

Output

In order to get the field labels use the menu in the ABAP editor GOTO->Text Elements->Selection Texts.

All the input fields will be displayed in a table.

Just check the Dictionary Ref checkbox and press enter.

The Text ( Field Label ) will be automatically read from the Data Element. Now save, activate, go back and run
the program again.

Now place the cursor on the input field and press F1 key to get the documentation from the data element.

Actually this field label and documentation are maintained in the Data Element MATNR.
So if we want to create a table with two fields as FirstName and SecondName, then only one domain is
sufficient with data type as CHAR and length say 20. But we need two different data elements in order to
display different field labels and documentation for both the fields.

How to create a domain in SAP?


To create a domain go to t-code SE11.

Select the Domain radio button, enter the the name of the domain that you want to create and press create.

Enter the short description. Place the cursor in the data type and press F4 to get the list of SAP data types.

In the popup window select the correct data type.

Enter the number of characters. Enter the decimal places if it applicable to data type that you have selected.
Save and activate the domain.

How to create a Data Element in SAP?


To create a data element go to t-code SE11.

Select the Data type radio button, enter the name of the data element and press create.

Select the Data Element radio button and press continue.

Enter short description. Assign a domain to the data element. Press field label tab to maintain the field labels for
thedata element.

Enter the field labels, Save and activate the data element.

How to create a SAP table?


Every table has a unique name and consists of rows and columns. The number of columns in a table is fixed but
can have any number of rows.
ABAP dictionary handles the DDL part of SQL in SAP. Go to ABAP dictionary (SE11) to create a SAP table.
Enter the name of the table to be created and press enter.

Enter a proper short description for the table and maintain delivery class as A'(Application Table). Now press on
Fields tab to maintain the fields of the table.

Enter the fields of the table and maintain the proper data elements for the table fields. You can use the standard
data elements or you can create your own data elements.

Maintain the primary key and press save. To maintain the technical attributes of table like tablespace, size etc.
press the Technical attributes button on application toolbar.

Enter Data class, Size category and Save.

Now press back, save and activate the table.

Maintain test data in SAP table


After creating a table you can test it by maintaining a couple of entries in the table. Follow the below mentioned
procedure to maintain entries in the table. But this procedure must be used only in testing or development
environment not in production environment.
Display the table in ABAP Dictionary(SE11). Use the menu path Utilities->Table Contents->Create Entries.

If

this menu path

is

disabled

then

go

to

Delivery

and

Maintenance

enter Display/Maintenance Allowed in Data Browser/Table View Maint. listbox.

Save and activate the table. Then go back to menu path Utilities->Table Contents->Create Entries.

tab

and

Enter some test values in the fields and press save.

Observe the message in the status bar. To display the values in the table go to Utilities->Table Contents>Display

In the selection screen enter the selection criteria if you want to filter the records you want to display and press
execute.

All

the

records

in the selection screen.

in

the

table

will

be

displayed

if

no

selection

criteria

specified

What are Primary Keys and Foreign Keys?


A primary key is a field or group of fields that uniquely identify a record in a table. Primary key fields cannot be
NULL and cannot contain duplicate values.
If you want to link two tables, then primary key of one table will be added to another table where primary key of
first table will be become the foreign key of second table.
Consider the following two tables.
Department Table
DEPARTMENT_ID

DEPARTMENT_NAME

(PRIMARYKEY)
01

Computers

02

Physics

03

Electronics

Employee Table
EMPLOYEE_ID

NAME

PLACE

(PRIMARY KEY)
001

Jim

New York

002

Jack

London

003

Robin

Sydney

004

Raj

Bangalore

If you want to link department table and employee table, then add the primary key of department table i.e.
Department_ID to employee table. Department_ID becomes the foreign key of employee table and Department
table becomes the check table.
Employee table after creating foreign key.
EMPLOYEE_ID

NAME

PLACE

(PRIMARY KEY)

DEPARTMENT_ID
(FOREIGN KEY)

001

Jim

New York

01

002

Jack

London

01

003

Robin

Sydney

02

004

Raj

Bangalore

03

The main purpose of the foreign key is data validation. This will not allow entering a Department_ID in the
employee table that is not there in the department table. For example if you try to create a record in employee
table with Department_ID as 04, it will throw an error.

How to create a Foreign Key in SAP table?


The purpose of the foreign key is to validate the data that is being entered into a table by checking entries in a
check table. Foreign keys are checked by the front end user interface only and it is not checked if you issue a
direct a SQL statement to update the database.
Follow the steps given below to create a foreign key in SAP table.
Step 1: Open the table in Data Dictionary (SE11) for which you want to create a foreign key. Select the field for
which you want to create the foreign key and press Foreign Keys button.

Step 2: In the popup window enter the check table name and press Generate proposal button.

Step 3: The system proposes the foreign key relation based on the domain. Check that the foreign key
relationship proposed by the system is correct and press copy.

Foreign key is created, now save and activate the table. To check the foreign key go to menu path Utilities>Table Contents->Create Entries.

Try to create an entry in Zemployee table with Department ID that is not there in the Department table. Enter
the values and try to save the entry.

Observe the error message in the status bar. The user interface does the foreign key validation before creating
the entries.

Das könnte Ihnen auch gefallen