ABAP DATA DICTIONARY

SAP stores all data in the form of tables in abap dictionary.This is a vital ,individual and edicated data base for SAP.

Here you can learn every thing regarding ABAP DICTIONARY.

All your comments are welcome.


ABAP DICTIONARY OVER VIEW



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
What-is-dataelement-1
In order to get the field labels use the menu in the ABAP editor GOTO->Text Elements->Selection Texts.
What-is-dataelement-2
All the input fields will be displayed in a table.
What-is-dataelement-3
Just check the Dictionary Ref checkbox and press enter.
What-is-dataelement-4
The Text ( Field Label ) will be automatically read from the Data Element. Now save, activate, go back and run the program again.
What-is-dataelement-5
Now place the cursor on the input field and press F1 key to get the documentation from the data element.
What-is-dataelement-6
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?

To create a domain go to t-code SE11.
Domain-1
Select the Domain radio button, enter the the name of the domain that you want to create and press create.
Domain-2 Enter the short description. Place the cursor in the data type and press F4 to get the list of SAP data types.
Domain-3
In the popup window select the correct data type.
Domain-4
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?

To create a data element go to t-code SE11.
Data-Element-1
Select the Data type radio button, enter the name of the data element and press create.
Data-Element-2
Select the Data Element radio button and press continue.
Data-Element-3
Enter short description. Assign a domain to the data element. Press field label tab to maintain the field labels for the data element.
Data-Element-4
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.
table-1
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.
table-2
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.
table-3
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.
table-4
Enter Data class, Size category and Save.
table-5
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.
create-entries-1
If this menu path is disabled then go to Delivery and Maintenance tab and
enter “Display/Maintenance Allowed” in “Data Browser/Table View Maint.” listbox.
create-entries-2
Save and activate the table. Then go back to menu path Utilities->Table Contents->Create Entries.
create-entries-3
Enter some test values in the fields and press save.
create-entries-4
Observe the message in the status bar. To display the values in the table go to Utilities->Table Contents->Display
create-entries-5
In the selection screen enter the selection criteria if you want to filter the records you want to display and press execute.
create-entries-6
All the records in the table will be displayed if no selection criteria specified
in the selection screen.

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 (Primary Key) Department_Name
01 Computers
02 Physics
03 Electronics
Employee Table
Employee_ID (Primary Key) Name Place
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 (Primary Key) Name Place 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.
foreign-key-1
Step 2: In the popup window enter the check table name and press Generate proposal button.
foreign-key-2
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-3
Foreign key is created, now save and activate the table. To check the foreign key go to menu path Utilities->Table Contents->Create Entries.
foreign-key-4
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.
foreign-key-5
Observe the error message in the status bar. The user interface does the foreign key validation before creating the entries.

No comments:

Post a Comment