Create an ABAP Database Table and Relevant ABAP Dictionary Objects
Create a database table from scratch using ABAP development tools for Eclipse (ADT); use different Data Dictionary objects to define the fields; then fill the table with test data.
Tables are defined independently of the database in the ABAP Dictionary. When you activate the table in the Data Dictionary, the table is created in the underlying database.
The table in this tutorial will store bank account details for customers. The table will have the following columns (or fields):
client (key field)
account_number (key field)
bank_name (key field)
bank_customer_id
city
balance
currency
account_category
lastchangedat
Throughout this tutorial, replace ### or 000 with your initials or group number.
Step 1Create table
—
Create a table in your package:
Select (right-click) the package and choose New > Other ABAP Repository Object from the context menu:
Image depicting step1-new-repo-object
Enter the filter text Table > Database table, then choose Next.
Enter a name such as ZACCOUNTS_### - always replacing ### with your initials or group number - and a description, then choose Next.
step1b-table-name
Accept the proposed transport request and choose Finish.
The code for the table appears in a new editor. Ignore the annotations at the top for now.
Image depicting step1d-table-editor
Step 2Understand table fields
+
In the next step, you will define the table fields. First you need to understand your options:
Built-in ABAP types and new types
There are 3 ways to create a field for a database table:
Use an existing data element: The most powerful: A data element describes both the technical and semantic attributes of a field, such as a currency, or a customer name. You can define properties such as search help and (translatable) column header, and then use the same data element in many contexts. You often define the technical attributes of the data element in a domain, so they can be reused.
Create a new data element: If you want to reuse the benefits of a data element - that is, semantic attributes, such as reuse of translatable column headers - but a suitable one does not exist yet.
overview-domain-dtel
In this tutorial, you will create one domain and one data element. For the other fields, you will use a built-in type or existing data element.
System clients
One key field has been added automatically:
client : abap.clnt;
This specifies that the table is client-dependent.
Tables can be client-dependent or client-independent. Each client is a self-contained unit within an organization, such as a subsidiary. For client-dependent tables, the client is the first key field in the table.
The field is also specified as not null. This means that the type-dependent initial value is automatically assigned to this field for all newly created records.
Step 3Add field account number using built-in type
+
Now you will add the key field account_number, based on a built-in type.
Enter the following (including the period), then choose Code completion (Ctrl+Space):
ABAP
keyaccount_number:abap.
From the dropdown list, choose numc(len) and specify len as 8. Also, specify this key field as not null:
key account_number : abap.numc(8) not null;
Step 4Add field city using existing data element
+
In the editor, enter the name for your field, followed by a colon: city:. Ignore the error for now.
Enter the type, by entering /DMO/C and using auto-complete (Ctrl+Space).
Then add a semi-colon:
ABAP
city:/dmo/city;
Step 5Add field bank using new data element
+
Now add the key field bank_name, based on a new data element, z_bank_name_###. You will get an error, which you will also fix in this step.
Enter the following:
ABAP
keyfieldbank_name:z_bank_name_###;
Select the new data element and choose Get Quick Fix (Ctrl+1). From the list, choose Create data element … :
step5a-quick-fix-new-dtel
The Create data element wizard appears. Enter a name and description and choose Next:
step6a-new-dtel
Accept the default transport request and choose Finish:
You want your data element to have a character type. Enter the following:
Category : Predefined Type
Data Type : CHAR
Length : 55
Now enter the field labels and lengths:
step6b-dtel-details
Save and activate the data element (Ctrl+S, Ctrl+F3).
Go back to your table, ZACCOUNTS_###. Run a syntax check with Ctrl+F2. The error should disappear.
Step 6Add all other fields
+
Now add other fields, so your code looks as follows. The field Balance will cause an error. Ignore this for now.
Save your changes (Ctrl+S), but again, do not activate the table yet.
Step 8Change technical settings
+
Before you activate the table, change the technical settings at the top as follows (or copy the code at the end of this step):
The label is derived from the description you entered; leave this.
EnhancementCategory : Place your cursor immediately after the hash symbol (#), delete the existing text, then choose Auto-complete (Ctrl+Space):
step9a-tech-settings
Then choose #EXTENSIBLE_CHARACTER_NUMERIC from the dropdown list. Your table contains both character-type and numeric-type fields but does not contain any deep structures (such as a structure included within a table row).
Complete the other settings as follows (or copy the code below).
tableCategory : #TRANSPARENT = your table represents a table in the database.
Tables are defined independently of the database in the ABAP Dictionary. When you activate the table in the Data Dictionary, the table is created in the underlying database. There is no need for any code to define the data in the database, nor for any vendor-specific code. Your database tables will be created in any database supported by the ABAP server.
deliveryClass : #A = application table, which stores master data and transaction data (default)
Now, save (Ctrl+S) and activate (Ctrl+F3) your table. Your code should look like this:
ABAP
@EndUserText.label:'Table of Bank Accounts'@AbapCatalog.enhancementCategory:#EXTENSIBLE_CHARACTER_NUMERIC@AbapCatalog.tableCategory:#TRANSPARENT@AbapCatalog.deliveryClass:#A@AbapCatalog.dataMaintenance:#RESTRICTEDdefinetablezaccounts_###{keyclient:abap.clntnotnull;keyaccount_number:abap.numc(8)notnull;bank_customer_id:/dmo/customer_idnotnullbank_name:z_bank_name_###;city:/dmo/city;@Semantics.amount.currencyCode:'zaccounts_###.currency'balance:abap.curr(16,2);currency:/dmo/currency_code;account_category:abap.numc(2);lastchangedat:timestampl;}
Step 10Test yourself
+
Step 11Fill table: Create class
+
Finally, you will fill the table with three rows of test data:
First create the ABAP Class, by selecting your package and choosing New > ABAP Class from the context menu:
Image depicting step5-create-class
Enter a name ZCL_FILL_ACCOUNTS_### and description for your class (replacing ### with your group number or initials).
step15b-name-class
Assign a transport request and choose Finish.
The class appears in a new editor.
Step 12Add interface
+
Add the following interface to your class:
ABAP
interfacesif_oo_adt_classrun.
This interface provides a lightweight solution for executing an ABAP program without launching a full user interface.
It also lets you display text or data in the ABAP Console.
Add the implementation for the main method of this interface by selecting the interface name and choosing Add implementation… from the context menu.
step6a-add-intf
Step 13Copy code
+
Add the following code to the method implementation:
ABAP
DATA:lt_accountstype table ofZACCOUNTS_###."read current timestamp
GET TIME STAMPFIELDDATA(zv_tsl)."fill internal table
lt_accounts=VALUE#((client='100'account_number='00000001'bank_customer_id='100001'bank_name='Volksbank'city='Gaertringen'balance='200.00 'currency='EUR'account_category='01'lastchangedat=zv_tsl)(client='100'account_number='00000002'bank_customer_id='200002'bank_name='Sparkasse'city='Schwetzingen'balance='500.00 'currency='EUR'account_category='02'lastchangedat=zv_tsl)(client='100'account_number='00000003'bank_customer_id='200003'bank_name='Commerzbank'city='Nuernberg'balance='150.00 'currency='EUR'account_category='02'lastchangedat=zv_tsl))."Delete possible entries; insert new entries
DELETEFROMZACCOUNTS_###.INSERTZACCOUNTS_###fromtable@lt_accounts."Check result in console
out->write(sy-dbcnt).out->write('DONE!').
Save and activate ( Ctrl+S, Ctrl+F3 ) your code.
Run your class by choosing Run as Console Application (F9).
The output should look roughly like this.
step16a-console
Step 14Check your table in Data Preview
+
Select your table from the Project Explorer and choose Open With > Data Preview from the context menu (F8).
step17a-data-preview
Your table should look like this:
step17b-data-preview-2
You can also right click on the table and choose Copy All Rows as ABAP Value Statement from the context menu. You can then paste it into other code.
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 15
1. Create table2. Understand table fields3. Add field account number using built-in type4. Add field city using existing data element5. Add field bank using new data element6. Add all other fields7. Fix the error with the field `Balance`8. Change technical settings9. Save and activate table code10. Test yourself11. Fill table: Create class12. Add interface13. Copy code14. Check your table in Data Preview15. More Information
Joule
AI Notice
Joule is an AI assistant. Generative AI may produce inaccurate, incomplete, or biased information. Always verify important details before acting on them.
Conversations are sent to SAP-hosted large language models for processing. Do not include personal data, credentials, or confidential information in your messages.
Joule's responses are based on the SAP tutorial catalog and may not reflect the latest product changes. For authoritative guidance, consult the linked tutorials and official SAP documentation.