Wednesday, 10 April 2013

Step by step process for Creating Foriegn Key relation in abap

There are basically two ways for creating a table in ABAP Dictionary. Bottom Up approach and top-down approach. In bottom up approach we first create domains and data elements required for our table (through transaction SE11) and then go for table creation. While in Top-down approach we go for table creation and on the road ahead create the required data element and domain. Bottom-up approach is sometimes tedious as you have to carry out operations differently.
In this post we will be learning top-down approach to create a table with a foreign key. Please refer to the step by step process of doing the same.

STEP 1.  Go to ABAP Dictionary by typing transaction code SE11 in command field
go to se11 transaction 
STEP 2.Select the Database Table radio button and type the name of table you wish to create in the Text Field. Click on Create Button

create database table in abap

STEP 3. Write a short description for your table, based on the type of data you wish to store in table select delivery class. Click on Fields tab. Write the name of fields you wish to for your table. Assign a proper data element to the field. As we are creating a application table give your first field as mandt to make the table client dependent.
If you wish to create your own data element and domain, follow step 4 to step11.

create a foriegn key table

STEP 4:   Write the field name as 'EMP_ID'. If you want to make this field as primary key check the checkbox for it. Now give a proper name for data element in the corresponding field (ZEMPLOYEE_IDENTITY) and press ENTER.

creating database table

STEP 5. Click on SAVE button to save the table. After that a popup block shown as below appears. Click on local object button to save the table.

STEP 6. Double click on the data element "zemployee_identity" a popup window shall appear asking to create a new data element; Click on yes. Now a new screen will appear. Enter the short description in the provided text field. Also Give a name for domain field in the Data Type tab.

Creating data element


STEP 7: Click on Field label Tab. Please note that Field Labels are used to assign text element to the corresponding data element. The Field label we assign here is used to describe the field where the data element will be used at the time of input screen. After assigning field label  save the data element as in STEP 5. If the domain you have given in the data type field doesn't already exist then follow step 8 to step 10


creating field labels for data element

STEP 8: Go to data type tab and double click on domain text field. A pop up window will appear asking to create a new domain. Click on yes and proceed. Enter the Short description. Choose appropriate Data Type for your field, provide no of characters (this is the length of your domain), decimal places if any.

creating domain in abap

If you wish to provide any value range for your domain then follow step 9.
STEP 9. Click on value range tab. You can specify value range in two different ways.  Either by providing fixed values which are poss for domain or specify a lower limit and upper limit.

STEP10: Click on Check option to check if inconsistencies found. If not, then click on activate option to activate your domain. A success message stating "Object Activated" shall appear in status bar. Click on back button to return to Data element screen.

STEP 11: Again Click on Check option to check if inconsistencies found. If not, then click on activate option to activate your domain. A success message stating "Object Activated" shall appear in status bar. Click on back button to return to table creation screen.

STEP 12: Now in the field name column enter field name as "MATNR" and enter its data element also as "MATNR". Press ENTER Key and click on SAVE button. This is the field for which we will create foreign key.

STEP 13: Now go to Entry help/check tab. Select the Matnr field and click on  foreign key option. A popup as shown below shall appear. Click on yes and proceed.

create foreign key in abap


STEP 14: Enter short description and click on "generate Proposal button". And after that click on Copy Button.


STEP 15: Ensure that the Foreign key box is checked. Click on SAVE button to save the progress in creating table.


STEP 16: Click on Technical Setting button available at the Standard toolbar. There you would see the option to select data class. Now data class corresponds to the physical area in database where your table gets stored. The Data class APPL0 corresponds to the data which are not changed frequently and APPL1 corresponds to data which are frequently changed. APPL2 is organizational and customizing data that  changes seldom. Also select the size category based on number of records you project to store in the table. After that click on save button to save technical settings and then click on Back button to return to maintain table screen.


STEP 17: Go TO Extras-> Enhancement Category. Select the appropriate category based on whether you wish to later enhance your table or not. Better to select cannot be enhanced. Click on copy.

Enhancement Category

STEP 18: Click on Check option to check if inconsistencies found. If not, then click on activate option to activate your domain. A success message stating "Object Activated" shall appear in status bar. 

You have successfully created your table.

2 comments:

  1. Excellent work sir. please keep on adding more content related to abap such as open and native sql, debugging and runtime analyser and code inspector.

    ReplyDelete